Hello, my name is Diego, I've been working with jfreechart for a while now and I am happy with it so far. But, since my chart have been getting more and more complicated I am having a problem now creating a combined and overlaid chart.
I copied the code from the createCombinedAndOverlaidChart1() method of the sample code and discovered that when you add a TimeSeriesCollection with more than one series to the CombinedDataset, then you get this error when you try to draw the chart:
Exception occurred during event dispatching:
java.lang.ClassCastException: com.jrefinery.data.DefaultXYDataset
at com.jrefinery.data.SubSeriesDataset.getHighValue(SubSeriesDataset.java:104)
at com.jrefinery.data.CombinedDataset.getHighValue(CombinedDataset.java:221)
at com.jrefinery.data.SubSeriesDataset.getHighValue(SubSeriesDataset.java:104)
at com.jrefinery.chart.HighLowRenderer.drawItem(HighLowRenderer.java:114)
at com.jrefinery.chart.XYPlot.render(XYPlot.java:787)
at com.jrefinery.chart.OverlaidXYPlot.render(OverlaidXYPlot.java:181)
at com.jrefinery.chart.XYPlot.draw(XYPlot.java:739)
at com.jrefinery.chart.CombinedXYPlot.draw(CombinedXYPlot.java:380)
at com.jrefinery.chart.JFreeChart.draw(JFreeChart.java:618)
at com.jrefinery.chart.ChartPanel.paintComponent(ChartPanel.java:800)
at javax.swing.JComponent.paint(JComponent.java:687)
at javax.swing.JComponent.paintChildren(JComponent.java:498)
at javax.swing.JComponent.paint(JComponent.java:696)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:546)
at javax.swing.JComponent.paintChildren(JComponent.java:498)
at javax.swing.JComponent.paint(JComponent.java:669)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:23)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:54)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:91)
at java.awt.Container.paint(Container.java:960)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
at java.awt.Component.dispatchEventImpl(Component.java:2663)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Window.dispatchEventImpl(Window.java:914)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
----------------------
if you want to test this go to the createCombinedAndOverlaidChart1() method in the JFreeChartDemoBase and replace this line:
XYDataset timeSeriesData = DemoDatasetFactory.createTimeSeriesCollection2(); //10th line more & less
with:
XYDataset timeSeriesData = DemoDatasetFactory.createTimeSeriesCollection3();
which returns a TimeSeriesCollection with two series in it.
Is this a bug?, do you know any cool way to work this arround?, I thought about creating a TimeSeriesCollection for each series but then the code gets pretty messy. What do you think?
Error when creating combined and overlaid charts
Re: Error when creating combined and overlaid charts
Hi Diego,
In the original combined and overlaid chart implementation, it was necessary to use CombinedDataset, but that shouldn't be the case now, because each plot now controls its own dataset. Take a look at the CombinedXYPlotDemo.java file for an example.
Regards,
Dave Gilbert
In the original combined and overlaid chart implementation, it was necessary to use CombinedDataset, but that shouldn't be the case now, because each plot now controls its own dataset. Take a look at the CombinedXYPlotDemo.java file for an example.
Regards,
Dave Gilbert
Re: Error when creating combined and overlaid charts
Dave, thanks for your answer but the CombinedXYPlotDemo class wasn't very helpful because each subplot uses a Dataset that contains only one series in it.
My problem is that I need to create a subPlot with a TimeSeriesCollection that contains more than one BasicTimeSeries. This raises the same error than the one generated by the createCombinedAndOverlaidChart1 method with the change I specified before.
Regards,
Diego.
My problem is that I need to create a subPlot with a TimeSeriesCollection that contains more than one BasicTimeSeries. This raises the same error than the one generated by the createCombinedAndOverlaidChart1 method with the change I specified before.
Regards,
Diego.
Re: Error when creating combined and overlaid charts
Hi Diego,
Sounds like a bug then. I tried it out in the CVS version of JFreeChart, it works OK there, so it looks like the bug has been cleaned up along the way.
Regards,
Dave Gilbert
Sounds like a bug then. I tried it out in the CVS version of JFreeChart, it works OK there, so it looks like the bug has been cleaned up along the way.
Regards,
Dave Gilbert
Re: Error when creating combined and overlaid charts
I am currently working with 0.9.4 version of jfreechart, is the CVS version newer than that?.
Another one, how can I turn off one of the references at the foot of the Graph (I mean the ones with the colored square and the plot title next to it) when I am using Combined charts.
Thank you very much Dave!, my regards,
Diego.
Another one, how can I turn off one of the references at the foot of the Graph (I mean the ones with the colored square and the plot title next to it) when I am using Combined charts.
Thank you very much Dave!, my regards,
Diego.