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

Message ListMessage List     Post MessagePost Message

  real time demo of XY data
Posted by JSF on Nov-03-2016 22:42
Attachments:
I need helps!

actually i want a real time demo for showing the trajectory of the vehicles, which could be represented by a real time XY demo.

i tried to optimize and change the codes of xyzoomscroll and realtimedemo. but unluckily failed.

the function of OnChartUpdateTimer and drawChart may not work correctly.

and the attached file is about the oncharupdate and drawchart functions.

please help me, thanks very much!
fortest.txt

  Re: real time demo of XY data
Posted by Peter Kwan on Nov-04-2016 04:02
Hi JSF,

For your case, your code is very different from the realtimedemo sample code, but it is quite close to the xyzoomscroll sample code. I suggest you start from the xyzoomscroll sample code and change it to a line chart instead of a scatter chart (use XYChart.addLineLayer with Layer.setXData instead of XYChart.addScatterLayer).

For your case, to get started, you may use specify a fixed full range for the chart, such as:

// Please change the followings to the full range suitable for your case
m_ChartViewer.setFullRange("x", 0, 100);
m_ChartViewer.setFullRange("y", 0, 100);

Then you can add a chart update timer, and in the timer, you just need one line of code to refresh the chart:

m_ChartViewer.updateViewPort(true, false);

You can add code to update your data array so that the chart can show your realtime data.

The original sample code allows the user to drag a rectangle (instead of a square) for zooming. Even if the original x and y axis scale is 1:1, after zooming, the scale may not be 1:1. To ensure the scale is always 1:1, you can adjust the viewport to make sure it is always a square. For example, in the OnViewPortChanged method, you can check if the viewport is a square, and adjust the viewport width or height to make it a square. For example:

double vpDelta = m_ChartViewer.getViewPortWidth() - m_ChartViewer.getViewPortHeight();
if (vpDelta > 0)
{
    m_ChartViewer.setViewPortHeight(m_ChartViewer.getViewPortWidth());
    m_ChartViewer.setViewPortTop(m_ChartViewer.getViewPortTop() - vpDelta / 2);
}
else
{
    m_ChartViewer.setViewPortWidth(m_ChartViewer.getViewPortHeight());
    m_ChartViewer.setViewPortLeft(m_ChartViewer.getViewPortLeft() + vpDelta / 2);
}
m_ChartViewer.validateViewPort();

Hope this can help.

Regards
Peter Kwan