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

Message ListMessage List     Post MessagePost Message

  Real-time chart: x-axis
Posted by Philip on Sep-15-2020 03:59
If the x-axis is not labelled in a XY chart, do the values along the x-axis reflect the offsets into the array holding the data?

Data AcQuisition (DAQ) recorders can record sound/noise. Sometimes while recording, a user may want to add a note/annotation to explain the data as it is being recorded such as "engine started". I think your measurement cursor may be able to help. If I have a button labelled "Add note" and a user clicks it, the code would get the value of the x-axis for the measurement cursor and prompt the user to enter a note. The x-axis value would be index into the array holding the data. The data would be saved in a file and the notes and corresponding offsets would be stored in another file.

For playback of the data, is it possible to show the data points and notes in the same XY chart? They would appear/disappear as the user scrolled along the x-axis.

If the XY chart was on the left of the screen and a list of the annotations was on the right side of the screen, clicking a note, the code would get the offset into the data and the x-axis of the XY chart would automatically scroll to reveal the note and the surrounding data points. Is this possible?

I think an annotation cursor would be a very nice feature.


  Re: Real-time chart: x-axis
Posted by Peter Kwan on Sep-15-2020 14:39
Hi Philip,

What you need can certainly be done with ChartDirector.

If your code do not provide x-coordinates to the chart layers (that is, Layer.setXData is not used), ChartDirector will use the array index as the x-coordinates. Note that the array index refers to the array that is passed to ChartDirector for plotting (eg. the array used in addLineLayer or addDataSet). It is not necessarily the same as the array of your original data.

For example, for a chart that can zoom and scroll, you may have a very large array, and you only need to display a small portion of it on the chart at any instance. In our sample code, we usually only pass the visible part of the array to the chart for display. The exact code depends on your programming language. It may be by moving a pointer (in C++), or by slicing the array (eg. in C#). So the chart does not see the entire array. It only sees the visible part of the array.

For your case, if the chart can zoom and scroll, you need to keep track of the index to your full array. So if you might just create the x-coordinates as well. Just create an array and put the numbers 0, 1, 2, 3, ... in it as the x-coordinates. If you do not want the x-coordinates to appear on the x-axis, just set the x-axis label color to transparent.

In this way, when the use clicks on the chart, you can use getNearestXValue to obtain the x-value of the data point nearest to the mouse. You can then look up the value in your full array. When the chart is scrolled, you can find all annotations that are within the visible range and add them to the chart (or to just add a symbol to represent there is an annotation on the right). If you are using track cursors, you can add them in the track cursor drawing code, or you can add them directly in "drawChart" using BaseChart.addText or other methods.

When the user clicks on annotation on the right, you can programmatically scroll the chart (by adjusting the viewport) so that the annotated x-value is within the visible range.

In some of our sample code, there is a scrollbar to scroll the chart. The scrollbar is not part of ChartDirector but is an external control. When the user drags on the scrollbar, the scrollbar event handler "programmatically" adjust the viewport to scroll the chart. For your case, the button on the right can be handled similarly.

Peter Kwan

  Re: Real-time chart: x-axis
Posted by Philip on Oct-16-2020 04:28

In a previous post I explained that I wanted to dynamically add a note to the real time XY Chart; the note would describe a group of points which is mostly an anomaly. Using a mouse click I am able to add the text using BaseChart.addText() which was your suggestion in the last message.

When the chart fills up on the right, the points and the x-axis labels begin to shift to the left but the note does not. I want the note to shift with the points. Eventually the points and note will disappear.


  Re: Real-time chart: x-axis
Posted by Peter Kwan on Oct-17-2020 03:11
Hi Philip,

When the user clicks on the chart, you code should obtain the x data value that the user has clicked. For the real time chart sample code, it should be a value in the timeStamps array.

BaseChart.addText uses pixel coordinates, not data values. So to add the text, your code needs to convert the x data value to x pixel value.

The above is how the track cursor is drawn. It uses XYChart.getNearestXValue to get the nearest x data value, then use XYChart.getXCoor to convert that to pixel coordinates.

So for your case, it should be like:

// remember the position that the user has clicked
double xValue = c.getNearestXValue(mouseX);
.... store the xValue so we can use it after zooming/scrolling ....

// add text at that position
xCoor = c.getXCoor(xValue);
c.addText(xCoor, ........);

When the chart is zoomed or scrolled, as long as you use the same xValue, it will add the text at the same x data value position.

Peter Kwan