ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chart not updating
Posted by Alden on May-13-2011 18:33
Attachments:
Hi Peter,

I've been scratching my head over a problem for while now and cannot find a solution.
Please could you give some advice/direction?

Please see the attached class....

I'm trying to adapt the ZoomScrollDemo for my own purposes.
At instantiation, the loadData() method in this class gets the data read from a file by
another class (data model).
When new data is downloaded from my data server by my data model, the updateChart
method is called in this class to update the chart with the new data. However, the chart
does not update to reflect the new data.

What am I doing wrong?

Regards,

Alden
finance2.java
finance2.java

28.47 Kb

  Re: Chart not updating
Posted by Peter Kwan on May-17-2011 01:37
Hi Alden,

To trouble-shoot the problem, please check the followings:

(a) Have your code in if fact updated the data? You may set a break point in your code, and look at the data arrays (eg. timeStamp array) using your debugger, or you may simply print the data arrays out to the console.

(b) The Zoomable and Scrollable code is only plotting a certain part of your data. For example, the user may be zoomed to the range 2011-03-01 to 2011-03-31. If your updated data are outside of that range, it would not be visible.

One way to check if the chart has been updated is to add a timestamp to the chart. For example:

c.addTitle(new java.util.Date().toString());

With the above code, you can tell if you chart has been updated by looking at the chart title. If the chart title changes, but the chart contents do not change, it is probably because the data have not changed.

Hope this can help.

Regards
Peter Kwan

  Re: Chart not updating
Posted by Alden on May-17-2011 15:16
Hi Peter,

The data IS updating properly, the new timestamps are present when I loop through them.
I am just unsure of how to update the viewport to reflect all the new data.

How is this done?

Many thanks,
Alden

  Re: Chart not updating
Posted by Peter Kwan on May-18-2011 00:34
Hi Alden,

I am not too sure what you mean by "viewport to reflect all the new data". In your current code, suppose the user has scrolled to view the data in the year 2008 (say the user has scrolled to view Jan 1, 2008 to Dec 31, 2008), If you updated the data in the year 2008, the updated data should be reflected in the chart. Is this not happening?

Suppose the user has scrolled to view the data in the year 2008 (say the user has scrolled to view Jan 1, 2008 to Dec 31, 2008), and your code update some data in Jan 11, 2010, do you want the view to automatically scroll to include Jan 11, 2010 (to update the viewport to reflect all the new data), regardless of what the user has originally scrolled to? Are you always updating data by appending a new timestamp at the end? If this is the case, is it something similar to the "Realtime Chart" sample code?

Regards
Peter Kwan

  Re: Chart not updating
Posted by Alden on May-18-2011 02:12
Hi Peter,

I am downloading historical (daily) data to append to the end of the chart. My data class
downloads the data properly and splits it into the arrays that the charting class needs.

It happens in the following order:

1 - the data class reads saved data from a file line by line and then plots the data using
the charting class. (ie by instantiating a new charting class)
2- then I connect to my broker's API to download new data to add to the end of the chart
instantiated in the previous step.

The data is being downloaded and passed to the charting class correctly, but the chart is
not updating (using the "updateChart" method - see attached file) to show the new data.

I'm not sure how to go about updating/redrawing the chart so I can see the new data.
Simply calling the createChart(int, int) method in the class does not have any effect.

Hope you can help.

Alden

  Re: Chart not updating
Posted by Peter Kwan on May-18-2011 19:48
Hi Alden,

There are two main parts in your code:

(a) Your code loads up the data arrays.

(b) Your code asks ChartDirector to plot only a certain part of the data (not all of the data).

By reading your code, I see that your code asks ChartDirector to plot the last 90 days of the data in the range:

// In this demo, we obtain the horizontal scroll range from the actual data.
minDate = timeStamps[0];
dateRange = (timeStamps[timeStamps.length - 1].getTime() - minDate.getTime()) / 1000;

The above is computed based on the initial timeStamps. Your code has never updated the dateRange. So ChartDirector is always plotting the last 90 days of data within the range of the initial timeStamps. So if your updated data are outside of the initial date range, it will not be plotted, because the charting code asks ChartDirector to only plot within the dateRange computed using the initial data.

If the above is the cause of the problem, to solve the problem, please update the dateRange after updating your data.

Hope this can help.

Regards
Peter Kwan

  Re: Chart not updating
Posted by Alden on May-19-2011 03:48
That solved the problem! Thanks!