Display chartPanel from jcheckbox with different XYSeries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ouijden
Posts: 4
Joined: Mon Dec 22, 2014 5:44 pm
antibot: No, of course not.

Display chartPanel from jcheckbox with different XYSeries

Post by ouijden » Mon Dec 22, 2014 6:03 pm

Hello,
I have a problem related to displaying two different ChartPanel on jPanel when I selected JCkeckBox.
First of all, I should have chart with XYSeries (values are extracted from file) displayed on jPanel. when I have to select JCheckBox, I may update the Panel with new XYSeries (the values are update with new scale).
This is a part of code that i used to set collection:

public XYSeriesCollection[] set_collection(XYSeries ser[],int n)
{
XYSeriesCollection[] collection = new XYSeriesCollection[n];
for(int i=0;i<n;i++)
{
collection = new XYSeriesCollection();
collection.addSeries(ser);
}
return collection;
}
So, the question is what is the best solution to set correct data on the ChartPanel?
Thank you :)

ouijden
Posts: 4
Joined: Mon Dec 22, 2014 5:44 pm
antibot: No, of course not.

Re: Display chartPanel from jcheckbox with different XYSerie

Post by ouijden » Tue Dec 23, 2014 12:58 pm

I find a solution related to add listener to jcheckBox element.
so I add this part of code on my class:
"
JCheckBox cbx_gest_Analog = new JCheckBox("");
cbx_gest_Analog.setBounds(775, 55, 26, 23);
ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
AbstractButton abstractButton = (AbstractButton)changeEvent.getSource();
ButtonModel buttonModel = abstractButton.getModel();
if(pressed){
panel_g.repaint();
panel_g.updateUI();
SelCan.dessiner_angChanAutoScale();
}
} } };
cbx_gest_Analog.addChangeListener(changeListener); "
This function work correctly with my code, Now I have to update the content of my two ChartPanel and scale for each one.
Any help please?
I can add more information to clarify.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Display chartPanel from jcheckbox with different XYSerie

Post by John Matthews » Wed Dec 24, 2014 5:30 pm

You might get some ideas from the example shown here.

ouijden
Posts: 4
Joined: Mon Dec 22, 2014 5:44 pm
antibot: No, of course not.

Re: Display chartPanel from jcheckbox with different XYSerie

Post by ouijden » Fri Dec 26, 2014 4:28 pm

Thank you John, it was very helpful
In my case I have to display an array of XYPlot. so if I select the checkbox, a new XYPlot[] will be created (with new scale(NumberAxis)).
Is it possible? or I should use a thread for that?

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Display chartPanel from jcheckbox with different XYSerie

Post by John Matthews » Sat Dec 27, 2014 5:52 am

Yes; if you update the model (dataset), the view (chart panel) will update itself in response.

Locked