multiple jfree chart in a single page

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
debanjan
Posts: 4
Joined: Tue Sep 09, 2014 10:46 am
antibot: No, of course not.

multiple jfree chart in a single page

Post by debanjan » Tue Sep 09, 2014 10:51 am

Hi ,
I,m new to jfree chart. I have successfully generate a time series chart. Now I want to generate multiple jfree chart in a single page. What is the way ?
Am using this code

JFreeChart Chart = ChartFactory.createTimeSeriesChart("EAI WEBSERVER HIT DETAILS","TIME","Count",my_data_series,true,true,false);
Chart.setBorderVisible(true);
Chart.setBackgroundPaint(new GradientPaint(0, 0, Color.cyan, 200,200, Color.red, false));
if (Chart != null)
{
int width = 1000;
int height = 700;
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, Chart, width, height);
}

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: multiple jfree chart in a single page

Post by John Matthews » Tue Sep 09, 2014 9:05 pm

Create a ChartPanel for each JFreeChart and add them to a panel haven a suitable layout, as suggested here.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: multiple jfree chart in a single page

Post by david.gilbert » Tue Sep 09, 2014 9:52 pm

For server side chart generation, you need to return HTML from one request that includes IMG tags with 'src' attributes that make additional requests to the server for PNG or JPEG files containing charts. Search Stack Overflow and you'll probably find something more helpful (I'm not a web app specialist). For example:

http://stackoverflow.com/questions/1255 ... in-servlet

With SVG support in browsers improving a lot, you might also want to consider embedding SVG encodings of JFreeChart in your HTML pages using JFreeSVG. I'm working on some enhanced SVG export for the 1.0.20 release, similar to what has already been done for Orson Charts:

http://www.object-refinery.com/blog/blog-20140509.html
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

debanjan
Posts: 4
Joined: Tue Sep 09, 2014 10:46 am
antibot: No, of course not.

Re: multiple jfree chart in a single page

Post by debanjan » Sat Sep 13, 2014 7:21 am

yes , I have successfully generate multiple graph in a page using this code

final DefaultCategoryDataset result1 = new DefaultCategoryDataset();
final DefaultCategoryDataset result2 = new DefaultCategoryDataset();
result1.addValue(Integer.parseInt(heap.get(0)), "server1" , "Type 1");
result1.addValue(Integer.parseInt(heap.get(1)), "server1" , "Type 2");

result2.addValue(Integer.parseInt(heap.get(1)), "server2" , "Type 1");

final CategoryDataset dataset1 = result1;
final NumberAxis rangeAxis1 = new NumberAxis("Value");
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
final LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
final CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
subplot1.setDomainGridlinesVisible(true);

final CategoryDataset dataset2 = result2;
final NumberAxis rangeAxis2 = new NumberAxis("Value");
rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
final BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
final CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
subplot2.setDomainGridlinesVisible(true);

final CategoryAxis domainAxis = new CategoryAxis("Category");
final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
plot.add(subplot1, 2);
plot.add(subplot2, 1);

final JFreeChart chart = new JFreeChart(
"Combined Domain Category Plot Demo",
new Font("SansSerif", Font.BOLD, 12),
plot,
true
);
if (chart != null)
{
int width = 1000;
int height = 700;
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
}

Look at the code ... for subplot 1 they used lineshape and for sub plot 2 Bar

But now I'm stuck in generating multiple thermometer plot in a single page. Is there anything like Lineshape and Bar for thermometer
I have used the following code to generate single thermometer

final DefaultValueDataset dataset = new DefaultValueDataset(new Double(50));
final ThermometerPlot plot = new ThermometerPlot(dataset);
plot.setUnits(plot.UNITS_NONE);
final JFreeChart chart = new JFreeChart("Free Heap Memory", // chart title
JFreeChart.DEFAULT_TITLE_FONT,
plot, // plot
true); // include legend
plot.setOutlineVisible(false);
plot.setSubrangeInfo(ThermometerPlot.NORMAL, 30.0, 100.0, 0.0, 100.0);
plot.setSubrangeInfo(ThermometerPlot.WARNING, 10.0, 20.0, 0.0, 100.0);
plot.setSubrangeInfo(ThermometerPlot.CRITICAL, 0.0, 10.0, 0.0, 100.0);
if (chart != null)
{
int width = 1000;
int height = 700;
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, chart, width, height);
}
Any help will be highly appreciated. Thanx

Locked