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

Message ListMessage List     Post MessagePost Message

  Mix line and scatter layers
Posted by Alejandro on Mar-06-2018 20:37
Attachments:
Hi.
I am facing a problem when trying to mix linear and scatter data. Let´s suppose we need to plot two data:

1.- Train speed: we have, for example, 80000 samples of train speed. So, our X-axis is a number representing the timestamp of the sample; the Y-axis is the speed itself.
2.- Along the track there are signals which are discrete elements. The train crosses the signals while running. In this case the X-axis is again a timestamp when the train crossed the signal and the Y-axis can be any number (1 for example) just to indicate that the train crossed that signal.

Attached you can find a file showing the described situation.
We want to use a Multi Chart with two of them, one for the speed and another one for the signals as shown on the attached file.
When defining a line layer, you put the DoubleArray with the complete collection of data for Y-axis (speed data) using addDataSet. The complete collection for the X-axis is set using the function setLabels with another DoubleArray for its values. As you notice, there is no connection between the collection of X and Y axis data. Just when put together using the same line layer it supposses that there is a one-by-one correspondence between the two DoubleArrays which must have the same size.
The problem arises when defining a scatter layer for the signals data. In this case we don´t have values for all the X-axis as in the case for speed data. We only have discretes values. In this case, ¿how can we tell the charts that the X-axis range for both charts is the same? The definition of the scatter layer needs two DoubleArrays, one with the X values (the timestamp when the train crosses the signal), and another with the Y values (in this case just a number to place a symbol in the graph). We can assume that the function setLabels must use the same data that in the case for speed chart.
Unfortunately, this does not work. The signals are plotted in points with no relation with the other graph. I think that the scatter chart plots one signal in, for example, the point 2500 but that point does not correspond with the point 2500 of the speed series. It is like both charts have different X axis references.
The problem is even worse as there are many signals whose X data do not match any of those for the speed data. I mean there can be a signal at point 2510 but there is no point defined at this value on X axis for speed data.
Any suggestion or hint to overcome this problem?

Thanks for your attention.
attached.jpg

  Re: Mix line and scatter layers
Posted by Peter Kwan on Mar-06-2018 23:51
Hi Alejandro,

You can use Axis.syncAxis to synchronize the x-axes of the two charts. For example:

// Make the bottom chart x-axis scale the same as that of the top chart
bottomChart->xAxis()->syncAxis(topChart->xAxis());

In this way, the data points of the two charts will align based on the x coordinates.

Hope this can help.

Regards
Peter Kwan

  Re: Mix line and scatter layers
Posted by Peter Kwan on Mar-06-2018 23:58
Hi Alejandro,

Note that in the code in my last message, I assume in your code, the x-coordinates are used as x-data, not x-axis labels. It is like:

LineLayer *layer = c->addLineLayer(DoubleArray(yData, count), ....);

// The xData are the x-coordinates, not the axis labels.
// By default, the x-axis labels will automatically be generated by ChartDirector based
// on xData, just the y-axis labels are automatically generated by ChartDirector based
// on data.
layer->setXData(DoubleArray(xData, count));

Regards
Peter Kwan

  Re: Mix line and scatter layers
Posted by Alejandro on Mar-07-2018 22:06
Ok. Thank you very much for your answer. I´ve implemented the axis sync and it works.

Yes, in fact, I found that there is a function to set up the x values (setXData).

Additionally I find that in a MultiChart the mouse events are only dispatched for the so declared main chart. So, in the case of a mouse line tracking, the vertical line is redrawn only while mouse is moving over the main chart but not over the others. In my example, as I´ve defined the speed chart as the main one the vertical line is updated while mouse is moving over it, but when the mouse is placed over the secondary chart of the signals, the vertical line is not updated and gets stuck on the position it was on the main chart.
Is there any way to achieve that the vertical line is updated when the mouse is moving over any of the charts of a MultiChart composition?

Thanks in advance.

  Re: Mix line and scatter layers
Posted by Peter Kwan on Mar-08-2018 04:09
Hi Alejandro,

May be you can try to set the main chart to the MultiChart itself, like:

myChart->setMainChart(myChart);

Regards
Peter Kwan