Hello,
I've ran your application (well, I moved the code to a NetBeans application but it's pretty much your code).
I've been able to reproduce the error you reported
here when exporting to XML. We are investigating it.
However, I've been able to export and import the chart using tej without many problems. I've only modified/corrected a few things:
- I've commented the initialization of the chart size because I've placed the chart at design time so it already has a size:
Code: Select all
//tChart1.setBounds(new Rectangle(0, 0, 500, 500));
- In saveItem button, I've uncommented the line where you are exporting the chart to a tej and I've commented the line where you export the chart to an xml. Also, I've slightly changed the path:
Code: Select all
tChart1.getExport().getTemplate().toFile("c:\\tmp\\tt23.tej");
//tChart1.getExport().getTemplate().toXML("c:\\tmp\\tt23.xml");
- In saveItem button I've commented the line where you set a text to the first label. note you are doing this after clearing the labels, so it gives an IndexOutOfBoundsException. I've also commented the repaint:
Code: Select all
bottom.getLabels().getItems().clear();
/*bottom.getLabels().getItems().set( 0, "new-1");
tChart1.repaint();*/
Here you have the complete saveItem action:
Code: Select all
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (tChart1 != null) {
try {
tChart1.setText("Stored chart");
tChart1.getSeries(0).setTitle("StoreA");
tChart1.getSeries(1).setTitle("StoreB");
Axis bottom = tChart1.getAxes().getBottom();
System.out.println(bottom.getLabels().getItems().size());
bottom.getLabels().getItems().add((double) 1, "MyXLabel-1");
bottom.getLabels().getItems().add((double) 2, "MyXLabel-2");
tChart1.repaint();
JOptionPane.showMessageDialog(null, "Current tchart will be stored");
tChart1.getExport().getTemplate().toFile("c:\\tmp\\tt23.tej");
//tChart1.getExport().getTemplate().toXML("c:\\tmp\\tt23.xml");
tChart1.getAspect().setView3D(true);
tChart1.setText("New Chart");
tChart1.getSeries(0).setTitle("new A");
tChart1.getSeries(1).setTitle("new B");
bottom = tChart1.getAxes().getBottom();
System.out.println(bottom.getLabels().getItems().size());
bottom.getLabels().getItems().clear();
/*bottom.getLabels().getItems().set( 0, "new-1");
tChart1.repaint();*/
} catch (IOException ex) {
}
}
}
});
- I've modified the openItem button to import the tej and I've added the refreshControl call mentioned
previously.
Code: Select all
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (tChart1 != null) {
try {
tChart1.setChart(tChart1.getImport().getTemplate().fromFile("c:\\tmp\\tt23.tej")); //load fail
//tChart1.getImport().getTemplate().fromXML("c:\\tmp\\tt23.xml");
//tChart1.updateUI();
//tChart1.repaint();
tChart1.refreshControl();
} catch (Exception ex) {
}
}
}
});