JFreeChart SlidingCategoryDataset chart update only axis
Asked Answered
T

1

2

I have implemented a Box and Whisker Chart with data from a csv file.
It has many categories and was displayed very squeezed on the screen.
So I decided to use a SlidingCategoryDataset with a JSlider as mentioned here.

I think my new class with code from SlidingCategoryDataset that extends DefaultBoxAndWhiskerDataset works fine because the category labels on the x-axis are updated correctly. BUT the bars in the chart stay the same and do not update anytime no matter what I do. Even more confusing is that the tool tips of the bars do update correctly.
When I reach the end of the dataset with the slider and display e.g. 10 categories at once and there are e.g. only 9 left, the chart displays 9 bars correctly but instead of hiding the first bar it hides the last bar (axis and tool tip are updated correctly).

I looked for a solutuion with google but did not find an answer for my problem. So I tried it by myself by using all avaible update and repaint methods because I think it must be a GUI problem but with no success. You can see my update method here:

private void sliderChanged(){
    int val = slider.getValue();
    sData.setFirstCategoryIndex(val);// my sliding dataset
    chart = ChartDrawer.draw(sData); // to draw chart again should be unnecessary
    chart.fireChartChanged();
    chartPanel.setChart(chart);
    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.updateUI();
    repaint();
}

I am a bit desperate now. Can somebody help me please? Or does somebody know another way to display many categories, that is working?
Thanks a lot.

Tedric answered 12/9, 2012 at 13:15 Comment(0)
M
1

The paging approach works, and it scales well. The example shown uses buttons, but a spinner or slider would do as well.

Alternatively, you could compare your implementation to the SlidingXYDataset, cited here and discussed here.

Miocene answered 12/9, 2012 at 17:45 Comment(2)
Thank you for your answer. I tried it the way you mentioned in your other post and create a new Dataset every time the slider changes. Finally it works!Tedric
Excellent; now that it's working, you might see if a cache of datasets is warranted.Miocene

© 2022 - 2024 — McMap. All rights reserved.