Example usage for org.jfree.chart ChartFactory createGanttChart

List of usage examples for org.jfree.chart ChartFactory createGanttChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createGanttChart.

Prototype

public static JFreeChart createGanttChart(String title, String categoryAxisLabel, String dateAxisLabel,
        IntervalCategoryDataset dataset, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a Gantt chart using the supplied attributes plus default values where required.

Usage

From source file:org.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java

@Override
public JComponent render(DateGapAnalyzerResult result) {

    final TaskSeriesCollection dataset = new TaskSeriesCollection();
    final Set<String> groupNames = result.getGroupNames();
    final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
    final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
    final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
    for (final String groupName : groupNames) {
        final String groupDisplayName;

        if (groupName == null) {
            if (groupNames.size() == 1) {
                groupDisplayName = "All";
            } else {
                groupDisplayName = LabelUtils.NULL_LABEL;
            }//from w  w  w .  j a va2  s .  c  o m
        } else {
            groupDisplayName = groupName;
        }

        final TimeInterval completeDuration = result.getCompleteDuration(groupName);
        final Task completeDurationTask = new Task(groupDisplayName,
                createTimePeriod(completeDuration.getFrom(), completeDuration.getTo()));
        completeDurationTaskSeries.add(completeDurationTask);

        // plot gaps
        {
            final SortedSet<TimeInterval> gaps = result.getGaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : gaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    gapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }

        // plot overlaps
        {
            final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : overlaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    overlapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }
    }
    dataset.add(overlapsTaskSeries);
    dataset.add(gapsTaskSeries);
    dataset.add(completeDurationTaskSeries);

    final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0,
            GROUPS_VISIBLE);

    final JFreeChart chart = ChartFactory.createGanttChart(
            "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(),
            result.getGroupColumnName(), "Time", slidingDataset, true, true, false);
    ChartUtils.applyStyles(chart);

    // make sure the 3 timeline types have correct coloring
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();

        plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT,
                WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT));
    }

    final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size());
    final ChartPanel chartPanel = ChartUtils.createPanel(chart, ChartUtils.WIDTH_WIDE, visibleLines * 50 + 200);

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            ChartEntity entity = event.getEntity();
            if (entity instanceof PlotEntity) {
                cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
            }
            chartPanel.setCursor(cursor);
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            // do nothing
        }
    });

    final JComponent decoratedChartPanel;

    final StringBuilder chartDescription = new StringBuilder("<html>");
    chartDescription.append("<p>The chart displays the recorded timeline based on FROM and TO dates.</p>");
    chartDescription.append(
            "<p>The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.</p>");
    chartDescription.append(
            "<p>You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.</p>");

    if (groupNames.size() > GROUPS_VISIBLE) {
        final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
        scroll.setMinimum(0);
        scroll.setMaximum(groupNames.size());
        scroll.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                int value = e.getAdjustable().getValue();
                slidingDataset.setFirstCategoryIndex(value);
            }
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                int scrollType = e.getScrollType();
                if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                    int wheelRotation = e.getWheelRotation();
                    scroll.setValue(scroll.getValue() + wheelRotation);
                }
            }
        });

        final DCPanel outerPanel = new DCPanel();
        outerPanel.setLayout(new BorderLayout());
        outerPanel.add(chartPanel, BorderLayout.CENTER);
        outerPanel.add(scroll, BorderLayout.EAST);
        chartDescription.append("<p>Use the right <b>scrollbar</b> to scroll up and down on the chart.</p>");
        decoratedChartPanel = outerPanel;
    } else {
        decoratedChartPanel = chartPanel;
    }

    chartDescription.append("</html>");

    final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString());

    final DCPanel panel = new DCPanel();
    panel.setLayout(new VerticalLayout());
    panel.add(chartDescriptionLabel);
    panel.add(decoratedChartPanel);

    return panel;
}

From source file:org.eobjects.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java

@Override
public JComponent render(DateGapAnalyzerResult result) {

    final TaskSeriesCollection dataset = new TaskSeriesCollection();
    final Set<String> groupNames = result.getGroupNames();
    final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
    final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
    final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
    for (final String groupName : groupNames) {
        final String groupDisplayName;

        if (groupName == null) {
            if (groupNames.size() == 1) {
                groupDisplayName = "All";
            } else {
                groupDisplayName = LabelUtils.NULL_LABEL;
            }/*from   w  ww.  j  ava2 s  .  c o m*/
        } else {
            groupDisplayName = groupName;
        }

        final TimeInterval completeDuration = result.getCompleteDuration(groupName);
        final Task completeDurationTask = new Task(groupDisplayName,
                createTimePeriod(completeDuration.getFrom(), completeDuration.getTo()));
        completeDurationTaskSeries.add(completeDurationTask);

        // plot gaps
        {
            final SortedSet<TimeInterval> gaps = result.getGaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : gaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    gapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }

        // plot overlaps
        {
            final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : overlaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    overlapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }
    }
    dataset.add(overlapsTaskSeries);
    dataset.add(gapsTaskSeries);
    dataset.add(completeDurationTaskSeries);

    final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0,
            GROUPS_VISIBLE);

    final JFreeChart chart = ChartFactory.createGanttChart(
            "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(),
            result.getGroupColumnName(), "Time", slidingDataset, true, true, false);
    ChartUtils.applyStyles(chart);

    // make sure the 3 timeline types have correct coloring
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();

        plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT,
                WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT));
    }

    final ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            ChartEntity entity = event.getEntity();
            if (entity instanceof PlotEntity) {
                cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
            }
            chartPanel.setCursor(cursor);
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            // do nothing
        }
    });

    final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size());

    chartPanel.setPreferredSize(new Dimension(0, visibleLines * 50 + 200));

    final JComponent decoratedChartPanel;

    StringBuilder chartDescription = new StringBuilder();
    chartDescription
            .append("<html><p>The chart displays the recorded timeline based on FROM and TO dates.<br/><br/>");
    chartDescription.append(
            "The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.<br/><br/>");
    chartDescription.append(
            "You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.");

    if (groupNames.size() > GROUPS_VISIBLE) {
        final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
        scroll.setMinimum(0);
        scroll.setMaximum(groupNames.size());
        scroll.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                int value = e.getAdjustable().getValue();
                slidingDataset.setFirstCategoryIndex(value);
            }
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                int scrollType = e.getScrollType();
                if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                    int wheelRotation = e.getWheelRotation();
                    scroll.setValue(scroll.getValue() + wheelRotation);
                }
            }
        });

        final DCPanel outerPanel = new DCPanel();
        outerPanel.setLayout(new BorderLayout());
        outerPanel.add(chartPanel, BorderLayout.CENTER);
        outerPanel.add(scroll, BorderLayout.EAST);
        chartDescription.append("<br/><br/>Use the right <b>scrollbar</b> to scroll up and down on the chart.");
        decoratedChartPanel = outerPanel;

    } else {
        decoratedChartPanel = chartPanel;
    }

    chartDescription.append("</p></html>");

    final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString());

    chartDescriptionLabel.setBorder(new EmptyBorder(4, 10, 4, 10));

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(decoratedChartPanel);
    split.add(chartDescriptionLabel);
    split.setDividerLocation(550);

    return split;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) {
    JFreeChart chart = null;//  w w  w. ja v a2s  .co m
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    CategoryDataset dataset = (CategoryDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean is3d = chartData.isChart3d();
    boolean legend = chartData.isLegend();

    if (type.equalsIgnoreCase("bar")) {
        if (is3d == true) {
            chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        } else {
            chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("stackedbar")) {
        if (is3d == true) {
            chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend,
                    true, false);
        } else {
            chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("line")) {
        if (is3d == true)
            chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        else
            chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
    } else if (type.equalsIgnoreCase("area")) {
        chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("stackedarea")) {
        chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("waterfall")) {
        chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("gantt")) {
        chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true,
                false);
    }

    CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(chartData.isDomainGridLines());
    plot.setRangeGridlinesVisible(chartData.isRangeGridLines());
    if (chartData.getGenerateMap() != null)
        plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator(""));

    int seriesCount = plot.getDataset().getColumnCount();
    if (chartData.getLineStokeWidth() > 0) {
        for (int index = 0; index <= seriesCount; index++)
            plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth()));
    }

    setCategorySeriesColors(chart, chartData);

    setCategoryExtensions(chart, chartData);

    return chart;
}

From source file:Negocio.Produccion.Planificacion.GanttDemo.java

/**
 * Creates a chart.//from   w  w w .j a  va  2 s . c o  m
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createGanttChart("Gantt Chart Demo", // chart title
            "Task", // domain axis label
            "Date", // range axis label
            dataset, // data
            true, // include legend
            true, // tooltips
            false // urls
    );
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
    return chart;
}

From source file:de.laures.cewolf.taglib.CewolfChartFactory.java

public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel,
        Dataset data) throws ChartValidationException {
    // first check the dynamically registered chart types
    CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType);
    if (factory != null) {
        // custom factory found, use it
        return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data);
    }//from www  .  jav a  2s.c o m

    switch (getChartTypeConstant(chartType)) {
    case XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, true, true);
    case PIE:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true);
    case AREA_XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case SCATTER:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case HORIZONTAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case LINE:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case STACKED_VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case TIME_SERIES:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false,
                false);
    case CANDLE_STICK:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case HIGH_LOW:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case GANTT:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data,
                true, false, false);
    case WIND:
        check(data, WindDataset.class, chartType);
        return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false,
                false);
    //case SIGNAL :
    //  check(data, SignalsDataset.class, chartType);
    //  return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
    case VERRTICAL_XY_BAR:
        check(data, IntervalXYDataset.class, chartType);
        return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case PIE_3D:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
    case METER:
        check(data, ValueDataset.class, chartType);
        MeterPlot plot = new MeterPlot((ValueDataset) data);
        JFreeChart chart = new JFreeChart(title, plot);
        return chart;
    case STACKED_AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case BUBBLE:
        check(data, XYZDataset.class, chartType);
        return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data,
                PlotOrientation.VERTICAL, true, false, false);

    case AUSTER_CICLOS:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data);

    default:
        throw new UnsupportedChartTypeException(chartType + " is not supported.");
    }
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Creates a chart of the actual view with a title.
 * @param title// www.ja v a 2 s  .  co m
 *            The title of the chart.
 */
protected final void makeChart(final String title) {
    DateTickUnit tick = null;
    switch (actualView) {
    case DAY:
        tick = new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("HH"));
        break;
    case WEEK:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("E, dd.MM."));
        break;
    case MONTH:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("d."));
        break;
    case YEAR:
        tick = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("M"));
        break;
    default:
        break;
    }
    gui.pnlGraph.setChart(ChartFactory.createGanttChart(title, "", "", createDataset(), true, true, false));
    gui.pnlGraph.getChart().getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
    gui.pnlGraph.getChart().getTitle().setMargin(5, 10, 5, 5);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setCategoryMargin(0.4);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setLowerMargin(0);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setUpperMargin(0);

    // chart.getCategoryPlot().getDomainAxis().getL

    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis()
            .setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));

    CategoryPlot plot = gui.pnlGraph.getChart().getCategoryPlot();
    DateAxis axis = (DateAxis) plot.getRangeAxis();
    axis.setMinimumDate(actualStart.getTime());
    axis.setMaximumDate(actualEnd.getTime());
    axis.setTickUnit(tick);

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setSeriesPaint(2, Color.red);
}

From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java

/**
 * Create the JFreeChart./*from   w  w  w.ja v  a  2s. c  om*/
 * @param dataset
 *            task list for the JFreeChart.
 * @return JFreeChart of tasks.
 */
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createGanttChart("", "", "", dataset, true, false, false);
    chart.getCategoryPlot().getDomainAxis().setCategoryMargin(0.4);
    chart.getCategoryPlot().getDomainAxis().setLowerMargin(0);
    chart.getCategoryPlot().getDomainAxis().setUpperMargin(0);

    chart.getCategoryPlot().getDomainAxis().setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    chart.getCategoryPlot().getDomainAxis().setTickLabelInsets(new RectangleInsets(0, 0, 0, 0));

    chart.getCategoryPlot().getDomainAxis()
            .setCategoryLabelPositions(new CategoryLabelPositions(
                    new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                            CategoryLabelWidthType.RANGE, 1),
                    new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                            CategoryLabelWidthType.RANGE, 1),
                    new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                            CategoryLabelWidthType.RANGE, 1),
                    new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                            CategoryLabelWidthType.RANGE, 1)));
    return chart;
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * //from  www .  ja  v  a 2  s  .com
 * DOC zhaoxinyi Comment method "createGanttChart".
 * 
 * @return
 */

public static JFreeChart createGanttChart(String chartAxies, Object ganttDataset) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    JFreeChart chart = ChartFactory.createGanttChart("", // chart title //$NON-NLS-1$
            Messages.getString("TopChartFactory.Categories"), // domain axis label //$NON-NLS-1$
            chartAxies, // range axis label
            (TaskSeriesCollection) ganttDataset, // data
            true, // include legend
            true, // tooltips
            false // urls
    );

    // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow
    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    // TDQ-5251~

    return chart;
}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates a gantt chart.//from  w w  w.  j av  a  2 s . c  om
 *
 * @return a gantt chart.
 */
public JFreeChart createGanttChart() {

    final String title = this.resources.getString("gantt.task.title");
    final String domain = this.resources.getString("gantt.task.domain");
    final String range = this.resources.getString("gantt.task.range");

    final IntervalCategoryDataset data = createGanttDataset1();

    final JFreeChart chart = ChartFactory.createGanttChart(title, domain, range, data, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    return chart;

}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

/**
 *
 *//*from w w w .j  a v  a  2 s  .  c  o  m*/
protected JFreeChart createGanttChart() throws JRException {
    //FIXMECHART legend/tooltip/url should come from plot?

    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createGanttChart(
            (String) evaluateExpression(getChart().getTitleExpression()),
            (String) evaluateExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()),
            (String) evaluateExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()),
            (GanttCategoryDataset) getDataset(), isShowLegend(), true, //FIXMECHART tooltip: I guess BarPlot is not the best for gantt
            false);

    configureChart(jfreeChart, getPlot());

    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    //plot.setNoDataMessage("No data to display");

    JRBarPlot barPlot = (JRBarPlot) getPlot();
    boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true
            : barPlot.getShowTickMarks().booleanValue();
    boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true
            : barPlot.getShowTickLabels().booleanValue();
    boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels().booleanValue();

    categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks);
    categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the category axis
    configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(),
            barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(),
            barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(),
            barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), false, null,
            null);
    ((DateAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks);
    ((DateAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the value axis
    configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(),
            barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(),
            barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(),
            barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), true,
            (Comparable) evaluateExpression(barPlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(barPlot.getRangeAxisMaxValueExpression()));

    BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer();
    categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
    categoryRenderer.setBaseItemLabelsVisible(isShowLabels);
    categoryRenderer.setShadowVisible(false);

    return jfreeChart;
}