Creating a Gantt Chart from a plot object
Creating a Gantt Chart from a plot object
Hi. how I can create a Gantt Chart without using the ChartFactory.createGanttChart() method?, I mean using a plot so I can use a renderer and a tooltip generator and customize the chart, let me know and thanks for your help
Re: Creating a Gantt Chart from a plot object
Hi Sergio,
Of course. If you look in the source code for the createGanttChart(...) method, and all the other methods in the ChartFactory class, you will see that they just create a regular JFreeChart object by putting together assorted classes (plots, axes, renderers, etc).
These 'ready-made' charts are just commonly used combinations to help people who don't want to get too close to the inner details of JFreeChart...there's nothing to stop you mixing and matching to create different charts, in fact I encourage it. An advantage of creating each of the objects yourself is that you can customise each one at the time of creating the chart, rather than having to fetch references and cast them to the correct subclass.
Regards,
Dave Gilbert
Of course. If you look in the source code for the createGanttChart(...) method, and all the other methods in the ChartFactory class, you will see that they just create a regular JFreeChart object by putting together assorted classes (plots, axes, renderers, etc).
These 'ready-made' charts are just commonly used combinations to help people who don't want to get too close to the inner details of JFreeChart...there's nothing to stop you mixing and matching to create different charts, in fact I encourage it. An advantage of creating each of the objects yourself is that you can customise each one at the time of creating the chart, rather than having to fetch references and cast them to the correct subclass.
Regards,
Dave Gilbert
Re: Creating a Gantt Chart from a plot object
Hi David,
I'm trying to use this code for gettting the chart displayed, but it doesn't display anything similar to a gantt chart
CategoryAxis categoryAxis = new HorizontalCategoryAxis("");
ValueAxis valueAxis = new VerticalNumberAxis("");
VerticalIntervalBarRenderer renderer = new VerticalIntervalBarRenderer();
renderer.setToolTipGenerator(new IntervalCategoryToolTipGenerator());
CategoryPlot plot = new VerticalCategoryPlot(dataset, categoryAxis, valueAxis, renderer);
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);
ChartUtilities.writeChartAsJPEG(out, chart, 900, 700);
What I'm doing wrong?, it's just that I don't know what plots I should use and how.. thanks for your support, I really appreciate it.
Regards, Sergio.
I'm trying to use this code for gettting the chart displayed, but it doesn't display anything similar to a gantt chart
CategoryAxis categoryAxis = new HorizontalCategoryAxis("");
ValueAxis valueAxis = new VerticalNumberAxis("");
VerticalIntervalBarRenderer renderer = new VerticalIntervalBarRenderer();
renderer.setToolTipGenerator(new IntervalCategoryToolTipGenerator());
CategoryPlot plot = new VerticalCategoryPlot(dataset, categoryAxis, valueAxis, renderer);
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);
ChartUtilities.writeChartAsJPEG(out, chart, 900, 700);
What I'm doing wrong?, it's just that I don't know what plots I should use and how.. thanks for your support, I really appreciate it.
Regards, Sergio.
Re: Creating a Gantt Chart from a plot object
There's a line that I shouldnt have included
ChartUtilities.writeChartAsJPEG(out, chart, 900, 700);
ignore it please, thanks
ChartUtilities.writeChartAsJPEG(out, chart, 900, 700);
ignore it please, thanks
Re: Creating a Gantt Chart from a plot object
This is the whole code,
CategoryAxis categoryAxis = new VerticalCategoryAxis("Activity");
DateAxis dateAxis = new HorizontalDateAxis("Date");
CategoryToolTipGenerator toolTipGenerator = new IntervalCategoryToolTipGenerator(sdf);
CategoryItemRenderer renderer = new HorizontalIntervalBarRenderer(toolTipGenerator);
Plot plot = new HorizontalCategoryPlot(dataset, categoryAxis, dateAxis,renderer);
JFreeChart chart = new JFreeChart("Activities for " + fdm,JFreeChart.DEFAULT_TITLE_FONT, plot, true);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
String filename = ServletUtilities.saveChartAsPNG(chart, 850, 700, info, request.getSession());
ChartUtilities.writeImageMap(out, filename, info);
out.flush();
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
out.println("<div align=center> <img src=" + graphURL + " height=850 width= 700 border=0 usemap=\"#" + filename + "\"> </div>");
CategoryAxis categoryAxis = new VerticalCategoryAxis("Activity");
DateAxis dateAxis = new HorizontalDateAxis("Date");
CategoryToolTipGenerator toolTipGenerator = new IntervalCategoryToolTipGenerator(sdf);
CategoryItemRenderer renderer = new HorizontalIntervalBarRenderer(toolTipGenerator);
Plot plot = new HorizontalCategoryPlot(dataset, categoryAxis, dateAxis,renderer);
JFreeChart chart = new JFreeChart("Activities for " + fdm,JFreeChart.DEFAULT_TITLE_FONT, plot, true);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
String filename = ServletUtilities.saveChartAsPNG(chart, 850, 700, info, request.getSession());
ChartUtilities.writeImageMap(out, filename, info);
out.flush();
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
out.println("<div align=center> <img src=" + graphURL + " height=850 width= 700 border=0 usemap=\"#" + filename + "\"> </div>");