TChart serializable problem

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
rubby
Newbie
Newbie
Posts: 38
Joined: Mon Aug 12, 2013 12:00 am

Re: TChart serializable problem

Post by rubby » Wed Jan 22, 2014 2:06 pm

Hello, Marc .

I got it. Thanks.

For the export and import problem,
Could you please run my code example , if it can not start, please let me know.
If you can run the code example, could you please try to click operation--> save.
Then click operation--> load.
I think you will find that something is wrong.
If you can load the saved tej or xml correctly, please let me know too.

I have tried many times, the tej can not loaded correctly.


Thanks again .

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChart serializable problem

Post by Yeray » Fri Jan 24, 2014 4:58 pm

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) {
                    }
                }
            }
        });
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

rubby
Newbie
Newbie
Posts: 38
Joined: Mon Aug 12, 2013 12:00 am

Re: TChart serializable problem

Post by rubby » Sun Jan 26, 2014 1:55 pm

Hello, Yeray:

Thank you so much.

For the export and import tej,
I should use:

Code: Select all

tChart.setChart( tChart.getImport().getTemplate().fromFile("c:\\tt23.tej"));

instead of

Code: Select all

  tChart.getImport().getTemplate().fromFile("c:\\tt23.tej");
this is why can not import a tej and show it.

However, for xml,
both of them are ok.

Code: Select all

                        tChart.getImport().getTemplate().fromXML("c:\\tt23.xml") ; //this is ok
                      tChart.setChart(tChart.getImport().getTemplate().fromXML("c:\\tt23.xml")); //this is ok too


For currently xml export and import, there is some errors with it.

java.lang.NullPointerException
at com.steema.teechart.drawing.Gradient.getCustomTargetRectangle(Gradient.java:448)

This will result the "MyXLabel-1" and "MyXLabel-2" do not showed.

I hope this conclusion will benefit other guys who come across similar problem.

In fact, i have another question, sorry.

Can i add some custom properties defined by myslef into xml or tej?
for example the created date, the author of this tchart, the data source path to create this tej.
thanks.

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChart serializable problem

Post by Yeray » Tue Jan 28, 2014 9:41 am

Hello,
rubby wrote:I hope this conclusion will benefit other guys who come across similar problem.
+1! Thanks for sharing.
rubby wrote:Can i add some custom properties defined by myslef into xml or tej?
for example the created date, the author of this tchart, the data source path to create this tej.
Yes, being a source code customer allows you to add any property you like to the TChart and they will be exported/imported with the other properties.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply