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:entropy.plan.visualization.GanttVisualizer.java

/**
 * Build the plan agenda//from  w  ww  .ja v a  2s .co m
 *
 * @param plan the plan to visualize
 * @return {@code true} if the generation succeeds
 */
@Override
public boolean buildVisualization(TimedReconfigurationPlan plan) {
    File parent = new File(out).getParentFile();
    if (parent != null && !parent.exists() && !parent.mkdirs()) {
        Plan.logger.error("Unable to create '" + out + "'");
        return false;
    }
    final TaskSeriesCollection collection = new TaskSeriesCollection();
    TaskSeries ts = new TaskSeries("actions");
    for (Action action : plan) {
        Task t = new Task(action.toString(),
                new SimpleTimePeriod(action.getStartMoment(), action.getFinishMoment()));
        ts.add(t);
    }
    collection.add(ts);
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());

    final JFreeChart chart = ChartFactory.createGanttChart(null, // chart title
            "Actions", // domain axis label
            "Time", // range axis label
            collection, // data
            false, // include legend
            true, // tooltips
            false // urls
    );
    CategoryPlot plot = chart.getCategoryPlot();
    DateAxis da = (DateAxis) plot.getRangeAxis();
    SimpleDateFormat sdfmt = new SimpleDateFormat();
    sdfmt.applyPattern("S");
    da.setDateFormatOverride(sdfmt);
    ((GanttRenderer) plot.getRenderer()).setShadowVisible(false);
    int width = 500 + 10 * plan.getDuration();
    int height = 50 + 20 * plan.size();
    try {
        switch (fmt) {
        case png:
            ChartUtilities.saveChartAsPNG(new File(out), chart, width, height);
            break;
        case jpg:
            ChartUtilities.saveChartAsJPEG(new File(out), chart, width, height);
            break;
        }
    } catch (IOException e) {
        Plan.logger.error(e.getMessage(), e);
        return false;
    }
    return true;
}

From source file:com.googlecode.logVisualizer.chart.turnrundownGantt.GanttChartBuilder.java

private JFreeChart createChart(final SlidingGanttCategoryDataset dataset) {
    this.dataset = dataset;
    final JFreeChart chart = ChartFactory.createGanttChart(getTitle(), null, null, dataset, false, true, false);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final CategoryItemRenderer renderer = plot.getRenderer();

    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.15f);
    plot.setRangeAxis(new FixedZoomNumberAxis());
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setAutoRange(false);
    plot.setRangeGridlinePaint(Color.black);
    setBarShadowVisible(chart, false);//from  w ww.j  av  a  2  s. c  o m

    for (final AreaInterval ai : ((TurnRundownDataset) dataset.getUnderlyingDataset()).getDataset())
        if (lastTurnNumber < ai.getEndTurn())
            lastTurnNumber = ai.getEndTurn();
    addDayMarkers(plot);
    addLevelMarkers(plot);
    addFamiliarMarkers(plot);

    plot.getRangeAxis().setUpperBound(lastTurnNumber + 10);

    renderer.setSeriesPaint(0, Color.red);
    renderer.setBaseToolTipGenerator(
            new IntervalCategoryToolTipGenerator("{1}, {3} - {4}", NumberFormat.getInstance()));

    return chart;
}

From source file:assig.Gantt.java

private JFreeChart createChart(final GanttCategoryDataset dataset) {
    JFreeChart chart;//from ww w .j  a  v  a  2s .c om
    if (FPanel.isFloating == false) {
        chart = ChartFactory.createGanttChart("Gantt ", // chart title
                "PRO", // domain axis label
                "TIME (ms)", // range axis label
                dataset, // data
                true, // include legend
                true, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createGanttChart("Gantt ", // chart title
                "PRO", // domain axis label
                "TIME (MicroSec)", // range axis label
                dataset, // data
                true, // include legend
                true, // tooltips
                false // urls
        );
    }
    CategoryPlot plot = chart.getCategoryPlot();

    DateAxis axis = (DateAxis) plot.getRangeAxis();

    axis.setDateFormatOverride(new SimpleDateFormat("S"));
    //axis.setMaximumDate(new Date(70));
    return chart;
}

From source file:test.GanttDemo1.java

/**
 * Creates a chart.//w w w. ja  v  a  2 s.c  o m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createGanttChart("", // chart title
            "Procesos", // domain axis label
            "Tiempo", // range axis label
            dataset, // data
            false, // include legend
            false, // tooltips
            false // urls
    );
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
    return chart;
}

From source file:org.endeavour.mgmt.controller.servlet.CreateProjectPlan.java

private void createReportPage(Document aDocument, TaskSeries aTaskSeries, Date aStartDate, Date aEndDate,
        String aDescription) throws Exception {

    TaskSeriesCollection theDataset = new TaskSeriesCollection();
    theDataset.add(aTaskSeries);//from ww  w .  j av  a  2s  .  c  o  m

    DateAxis theDateRange = new DateAxis(TIMELINE);
    theDateRange.setMinimumDate(aStartDate);
    theDateRange.setMaximumDate(aEndDate);

    JFreeChart theChart = ChartFactory.createGanttChart(aDescription, ARTIFACTS, null, theDataset, true, false,
            false);
    CategoryPlot theCategoryPlot = theChart.getCategoryPlot();
    theCategoryPlot.setRangeAxis(theDateRange);

    BufferedImage theChartImage = theChart.createBufferedImage(780, 520);
    ByteArrayOutputStream theOutputStream = new ByteArrayOutputStream();
    ImageIO.write(theChartImage, "png", theOutputStream);
    Image theDocumentImage = Image.getInstance(theOutputStream.toByteArray());
    aDocument.add(theDocumentImage);
}

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

private static JFreeChart createChart(IntervalCategoryDataset intervalcategorydataset) {
    JFreeChart jfreechart = ChartFactory.createGanttChart("Gantt Chart Demo", "Task", "Date",
            intervalcategorydataset, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F);
    DateAxis dateaxis = (DateAxis) categoryplot.getRangeAxis();
    dateaxis.setUpperMargin(0.20000000000000001D);
    GanttRenderer ganttrenderer = (GanttRenderer) categoryplot.getRenderer();
    ganttrenderer.setDrawBarOutline(false);
    ganttrenderer.setBaseItemLabelGenerator(new MyLabelGenerator(new SimpleDateFormat("d-MMM")));
    ganttrenderer.setBaseItemLabelsVisible(true);
    ganttrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT));
    return jfreechart;
}

From source file:one.TimeLineChart.java

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

From source file:graficos.GraficoGantt.java

private static JFreeChart crearGrafico(IntervalCategoryDataset cjto_datos) {
    JFreeChart grafico = ChartFactory.createGanttChart("Diagrama de Gantt", // Ttulo
            "Actividad", // Ttulo eje x
            "Fecha", // Ttulo eje y
            cjto_datos, // Datos
            true, // Incluir leyenda
            true, // Incluir tooltips
            false // Incluir URLs
    );/*from   w  ww . j av  a2 s  .c om*/
    grafico.setBackgroundPaint(new Color(240, 240, 240));
    grafico.getPlot().zoom(0.0);
    CategoryPlot categoriaPlot = (CategoryPlot) grafico.getPlot();
    GanttRenderer renderer = (GanttRenderer) categoriaPlot.getRenderer();
    renderer.setDrawBarOutline(true);
    // GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(102, 255, 102), 0.0f, 0.0f, new Color(102, 255, 102));
    renderer.setSeriesPaint(0, new Color(48, 239, 48));
    renderer.setSeriesPaint(1, Color.RED);
    grafico.getPlot().setOutlineVisible(true);
    return grafico;
}

From source file:GanttChart.Gantt.java

/**
 * Creates a chart./*ww  w.ja va  2  s .c om*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createGanttChart(this.nomeProgetto, // chart title
            "Attivit", // domain axis label
            "Data", // range axis label
            dataset, // data
            false, // include legend
            true, // tooltips
            true // urls
    );
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
    return chart;
}

From source file:view.GanttView.java

/**
 * Creates a chart./* ww  w . j av a 2s  .  c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final IntervalCategoryDataset dataset, String title) {
    final JFreeChart chart = ChartFactory.createGanttChart(title, // chart title
            "ACTIVITY", // domain axis label
            "DATE", // range axis label
            dataset, // data
            true, // include legend
            false, // tooltips
            false // urls
    );
    return chart;
}