Using multiple renderers causes an Exception

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Using multiple renderers causes an Exception

Post by tdk » Wed Feb 07, 2007 8:48 am

Folks'es,

i have a question/problem when using different renderers for a chart.
i have 4 XYSeries which i want to show in the following way:
- series 1, 2, and 3 should be drawn with a XYStepAreaRenderer
- series 4 should be drawn with a XYStepRenderer

however, when the plot is drawn i get the following exception:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Index
 'index' out of bounds.
    at org.jfree.chart.plot.XYPlot.getDomainAxisForDataset(XYPlot.java:2697)
    at org.jfree.chart.plot.XYPlot.drawDomainMarkers(XYPlot.java:2851)
    at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:2208)
    at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1039)
    at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1269)
    at javax.swing.JComponent.paint(JComponent.java:1003)
following are the jfree related bits of my code:

Code: Select all

        dataPoints = new XYSeriesCollection();
        dataPoints.addSeries(yellowThreshold);
        dataPoints.addSeries(orangeThreshold);
        dataPoints.addSeries(redThreshold);
        dataPoints.addSeries(values);

        lineChart = ChartFactory.createTimeSeriesChart("", "", "Day+Hour:Minute:Second",
                dataPoints, true, true, false);
        ((NumberAxis)lineChart.getXYPlot().getRangeAxis()).setNumberFormatOverride(new DecimalFormat() {
            public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) {
                return format((long)number, result, fieldPosition);
            }
            public StringBuffer format(long number, StringBuffer result, FieldPosition fieldPosition) {
                result.insert(fieldPosition.getBeginIndex(), ElapsedTime.format(number));
                return result;
            }
        });
        lineChart.getXYPlot().setRenderer(0, new XYStepAreaRenderer());
        lineChart.getXYPlot().setRenderer(1, new XYStepAreaRenderer());
        lineChart.getXYPlot().setRenderer(2, new XYStepAreaRenderer());
        lineChart.getXYPlot().setRenderer(3, new XYStepRenderer());
could there be a relation to the issue described in http://www.jfree.org/phpBB2/viewtopic.p ... +renderers?

thomas

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

Post by david.gilbert » Wed Feb 07, 2007 2:37 pm

Did you make any calls to mapDatasetToDomainAxis()?
David Gilbert
JFreeChart Project Leader

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

tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Post by tdk » Wed Feb 07, 2007 3:17 pm

No, i had not. but now i have:

Code: Select all

        xAxis.setLabelInfo(bands);
        lineChart.getXYPlot().setDomainAxis(0, xAxis);
        lineChart.getXYPlot().mapDatasetToDomainAxis(0, 0);
        lineChart.getXYPlot().mapDatasetToDomainAxis(1, 0);
        lineChart.getXYPlot().mapDatasetToDomainAxis(2, 0);
        lineChart.getXYPlot().mapDatasetToDomainAxis(3, 0);

        XYStepAreaRenderer renderer = new XYStepAreaRenderer();
        lineChart.getXYPlot().setRenderer(0, new XYStepRenderer(), false);
        lineChart.getXYPlot().setRenderer(1, renderer, false);
        lineChart.getXYPlot().setRenderer(2, renderer, false);
        lineChart.getXYPlot().setRenderer(3, renderer, false);
but the result is still the same exception:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Index
 'index' out of bounds.
    at org.jfree.chart.plot.XYPlot.getDomainAxisForDataset(XYPlot.java:2697)
    at org.jfree.chart.plot.XYPlot.drawDomainMarkers(XYPlot.java:2851)
    at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:2208)
    at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1039)
    at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1269)
    at javax.swing.JComponent.paint(JComponent.java:1003)
    at javax.swing.JComponent.paintChildren(JComponent.java:840)
thomas

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

Post by david.gilbert » Wed Feb 07, 2007 3:58 pm

OK, I've managed to reproduce the problem now. If you add a renderer to the XYPlot, but don't add a corresponding dataset, this exception is thrown. I've added the following bug to the database, and will look at how to fix this:

http://sourceforge.net/tracker/index.ph ... tid=115494
David Gilbert
JFreeChart Project Leader

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

tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Post by tdk » Wed Feb 07, 2007 4:14 pm

Dave,

i don't quite understand this. my data is a XYSeriesCollection which has 4 XYSeries (see initial posting). doesn't that qualify as 4 datasets?

confused,

thomas

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

Post by david.gilbert » Wed Feb 07, 2007 4:22 pm

No, it is one dataset containing four series. If you want four datasets, you need to create four instances of XYSeriesCollection, and add one series to each.
David Gilbert
JFreeChart Project Leader

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

tdk
Posts: 19
Joined: Mon Aug 29, 2005 3:17 pm
Location: Germany
Contact:

Post by tdk » Thu Feb 08, 2007 8:49 am

david.gilbert wrote:No, it is one dataset containing four series. If you want four datasets, you need to create four instances of XYSeriesCollection, and add one series to each.
oops, thanx it works now!

thomas

Locked