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
Display chartPanel from jcheckbox with different XYSeries
Re: Display chartPanel from jcheckbox with different XYSerie
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.
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.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Display chartPanel from jcheckbox with different XYSerie
You might get some ideas from the example shown here.
Re: Display chartPanel from jcheckbox with different XYSerie
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?
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?
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Display chartPanel from jcheckbox with different XYSerie
Yes; if you update the model (dataset), the view (chart panel) will update itself in response.