Hello,
I would like to use JFreeChart for a medical application we are building. I've serach the forum and looked into the FAQ but did not quite get an answer for the following use case:
Theoretically, I have several different charts, or to be pricise, I have the data for several different charts (y and x values). What I want is to lay all those charts as "layers" over each other, so I can easily see the visual difference.
The thing is, the y and x axis must be adjusted accordingly to the maximum and minimum of the data of all charts. Say I have chart data A, where the minumum is 0 and maximum is 100 (for one axis). Another chunk of chart data B has a minimum of -50 and a maximum of 80. The result now must be one chart (or let's say theses "two charts in one char component") with a minimum of -50 and a maximum of 100 for the axis.
Must I precalculate the min and max values for all chart data myself, or can I just go and say JFreeChart to render my charts, and it will adjust the axis automatically, so point of the curves is visible?
Thanks a lot for your help
Regards,
Ben
Overlay of several charts into one chart?
Since I've just created a chart similar to what you want to do I believe I can help you!
I will refer to classes, which you can find in the API and search further upon. I can also start of by saying that yes, it will automatically adjust the y-axis to fit the highest/lowest data item.
First you need to create a XYSeries for each chart data, that is for chart data A, chart data B etc. Check out the API.
Then just add all the XYSeries to the same XYSeriesCollection object. (The XYSeriesCollection class implements the XYDataset interface, which is the important thing. There are several other classes that implement the XYDataset interface).
After that, just add the XYSeriesCollection to a XYPlot with the method setDataset.
Add the XYPlot to the JFreeChart object you create (easily done via the constructor)
Then just add the JFreeChart object to a ChartPanel and add that into your application and it's done.
I will refer to classes, which you can find in the API and search further upon. I can also start of by saying that yes, it will automatically adjust the y-axis to fit the highest/lowest data item.
First you need to create a XYSeries for each chart data, that is for chart data A, chart data B etc. Check out the API.
Then just add all the XYSeries to the same XYSeriesCollection object. (The XYSeriesCollection class implements the XYDataset interface, which is the important thing. There are several other classes that implement the XYDataset interface).
After that, just add the XYSeriesCollection to a XYPlot with the method setDataset.
Add the XYPlot to the JFreeChart object you create (easily done via the constructor)
Then just add the JFreeChart object to a ChartPanel and add that into your application and it's done.
I might as well help you further if you get stuck with the chart not rendering.
I'd suggest you use one of the ChartFactory functions to create the JFreeChart.
If you do that, you won't have to add the XYSeriesCollection to an XYPlot manually. The ChartFactory function will itself create an XYPlot and add the supplied XYSeriesCollection (=XYDataset dataset).
If you however want to be able to customize it a little more, you can create your own XYPlot like I explained in my first post. Just remember that you'd need to create a y-axis (range-axis) and an x-axis (domain-axis) for the XYPlot. You'd also have to create a renderer for the XYPlot. (one of the subclasses to AbstractXYItemRenderer).
I'd suggest you use one of the ChartFactory functions to create the JFreeChart.
If you do that, you won't have to add the XYSeriesCollection to an XYPlot manually. The ChartFactory function will itself create an XYPlot and add the supplied XYSeriesCollection (=XYDataset dataset).
If you however want to be able to customize it a little more, you can create your own XYPlot like I explained in my first post. Just remember that you'd need to create a y-axis (range-axis) and an x-axis (domain-axis) for the XYPlot. You'd also have to create a renderer for the XYPlot. (one of the subclasses to AbstractXYItemRenderer).
Hello Siniz,
thanks a lot for your offer. I was not able to get started with it, but I will definitively later today. My goal is to have that "multi chart" as I explained above, and I need to paint the values of each nodes of the charts next to the node. For example, a chart with a node with an y-value of 20 has a small label next to it with "20" as it's text.
I don't know if this is possible out of the box, or do I need to create such a customized renderer? If yes, which renderer must I look for in the API?
My problem is at the moment, I don't have much time in the current project, I need to get that working chart finished until this friday, so your help is very welcome
Thanks!
thanks a lot for your offer. I was not able to get started with it, but I will definitively later today. My goal is to have that "multi chart" as I explained above, and I need to paint the values of each nodes of the charts next to the node. For example, a chart with a node with an y-value of 20 has a small label next to it with "20" as it's text.
I don't know if this is possible out of the box, or do I need to create such a customized renderer? If yes, which renderer must I look for in the API?
My problem is at the moment, I don't have much time in the current project, I need to get that working chart finished until this friday, so your help is very welcome

Thanks!