Hi ,
We have a requirement to generate multiple charts using jfree.The way needs is like for eg: if We pass three different data to create a step or xyline chart we need to generate three different graphs opening in the same window or by on close of one window the other graph window has to open one by one.Is there any way to acheive this.It will be greatfull to hear some ideas on the same.
We already got an idea of generating png through jsp files and opening it.But we need any other approach which has feasibility and proper.
Thanks,
SAT
Mutiple Charts Generation
Re: Mutiple Charts Generation
just create more instances of your class which extends JFrame and has ChartPanel inside. you can count the datasets and create many instances of that JFrame class passing the datasets simply even by constructors.
Re: Mutiple Charts Generation
Hi,
Thanks for your immediate response.But actually ours is a webbased application in which we are trying to open the jfree chart graph as a separate webpage.Our requirement is like when i am passing three sets of data to generate three graphs, all the three graphs has to get generated and open in a single webpage.It will be helpful if you advise us on how to acheive this.
Option 1:We tried by using the below code snippet as part of our servlet to generate chart and write it to the output stream.
Option2:Is There any other Approach where we can save the Chart to the Jsp..instead of writing it to a file or save to disk and again pick it from jsp...ie <img src=""/>
Thanks
SAT
Thanks for your immediate response.But actually ours is a webbased application in which we are trying to open the jfree chart graph as a separate webpage.Our requirement is like when i am passing three sets of data to generate three graphs, all the three graphs has to get generated and open in a single webpage.It will be helpful if you advise us on how to acheive this.
Option 1:We tried by using the below code snippet as part of our servlet to generate chart and write it to the output stream.
Code: Select all
double[][] series1 = new double[][]{ {2,2,9,9,9,9,10,10,11,11,22,22,37,37,144,144},{1445.16,1238.71,1238.71,1032.26,1032.26,825.81,825.81,619.35,619.35,412.90,412.90,206.45,206.45,0.00,0.00,0.00 }};
// double[][] series2 = new double[][]{ {2,2,2,2,4,4,6,6,10,10,15,15,24,24,37,37,88,88,433,433},{1858.06,1651.61,1651.61,1445.16,1445.16,1238.71,1238.71,1032.26,1032.26,825.81,825.81,619.35,619.35,412.90,412.90,206.45,206.45,0.00,0.00,0.00 }};
PlotOrientation orientation = PlotOrientation.HORIZONTAL;
DefaultXYDataset dataset= new DefaultXYDataset();
dataset.setGroup(new DatasetGroup("km"));
((DefaultXYDataset)dataset).addSeries("Cable : 1 ",series1);
//((DefaultXYDataset)dataset).addSeries("Cable : 2",series2);
JFreeChart chart = ChartFactory.createXYStepChart("StepChart","values","Range",dataset,orientation,true,true,false);
NumberTickUnit tickunits = new NumberTickUnit(100);
LogAxis xAxis = new LogAxis("Cycles (cumulative)");
XYPlot plot = chart.getXYPlot();
xAxis.setLowerBound(1);
xAxis.setUpperBound(100000);
plot.setRangeAxis(xAxis);
NumberAxis yaxis = new NumberAxis();
yaxis.setTickUnit(tickunits);
plot.setDomainAxis(yaxis);
ServletOutputStream opStream=response.getOutputStream();
//to wtite the chart to OutputStream.
ChartUtilities.writeChartAsPNG(opStream, chart , 1024, 760);
//to save the chart as PNG in File ssytem.
ChartUtilities.saveChartAsPNG(file, chart , 1024, 760);
Option2:Is There any other Approach where we can save the Chart to the Jsp..instead of writing it to a file or save to disk and again pick it from jsp...ie <img src=""/>
Thanks
SAT
Re: Mutiple Charts Generation
Hi Any other suggestion or reply on this
Thanks,
SAT
Thanks,
SAT
Re: Mutiple Charts Generation
Hi,
When we tried to pass the png image as part of response we are facing an issue like outofmemory exception.How to avoid or resolve this issue.Please advise.
Thanks,
SAT
When we tried to pass the png image as part of response we are facing an issue like outofmemory exception.How to avoid or resolve this issue.Please advise.
Thanks,
SAT
Re: Mutiple Charts Generation
Save the png image to a file on the server and return a reference to the file in the response.
Re: Mutiple Charts Generation
Hi,
As we freezed our requirement initial itself we dont have privilages to save or create folder to store image in our server.We need to directly manuplate the x-axis and y-axis values to generate the graph.It will be greatful if we get some other possible ways to acheive it.
Thanks ,
SAT
As we freezed our requirement initial itself we dont have privilages to save or create folder to store image in our server.We need to directly manuplate the x-axis and y-axis values to generate the graph.It will be greatful if we get some other possible ways to acheive it.
Thanks ,
SAT