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

Message ListMessage List     Post MessagePost Message

  Markers with Scatter Plots
Posted by Viks30 on Feb-26-2011 07:16
Hello Peter,

I am facing some issues wrt adding markers on my existing plot.

I currently have a plot that has 2 line layers.
LineLayer layer1 = c.addLineLayer(Y1)
LineLayer layer2 = c.addLineLayer(Y2, c.dashLineColor(current_color, Chart.DotLine));
c.xAxis().setLabels(X2);
c.xAxis().setLabelStep(25, 1);
These linelayers are plotted wrt timestamps seen in X2 array(or even X1). The datapoints for the same are in order of 1500-odd.

On top of these lines I wanted to place some markers. The place where they need to go are in XY [100,T1], [120,T2] and so on. I see that AddScatterLayer is the way to go about it.

The timestamps T1,T2...are in the same range as the above 2 line layers.
ScatterLayer scatterLayer = c.addScatterLayer(dataX3, dataY3, "",
        Chart.DiamondSymbol, 11, 0x008000);

Inspite of this, the utlimate result shows the Scatter-Graph symbols on the extreme end of X axis with the correct Y elevation. I am wondering if there can be any help to fix this. I tried the same problem removing the concept of timestamps (HH:mm:ss) with linenumbers and the symbols were displayed accurately.

Can you keep me posted.

Many Thanks,

  Re: Markers with Scatter Plots
Posted by Peter Kwan on Feb-26-2011 23:49
Hi Viks30,

For your case, as you use the Axis.setLabels API to set up the x-axis, the X2 are just labels on the x-axis. They are not the x-coordinates of the data points (just like the labels you see on the y-axis are not the y-coordinates of the data points). The X2 are treated as "names" for human reading only, and do not have any particular meaning to ChartDirector.

For your case, as the line layers do not have any x-coordinates (there is no setXData), ChartDirector will just use the array index 0, 1, 2, 3 ... as the x-coordinates of the corresponding data point.

If you add a scatter point at [100, T1], then the symbol will be added to the 101th point (the first point is 0). This is regardless of what the x-axis labels are.

If you want to add a scatter point to the point with the x-axis label "100", you would need to first find out what is the index of that point (eg. using Array.IndexOf(X2, 100), assuming X2 is an array of numbers), then use that index in the scatter layer.

Should you need further information, please feel free to contact me.

Regards
Peter Kwan

  Re: Markers with Scatter Plots
Posted by Viks30 on Mar-01-2011 03:47
Attachments:
Hello Peter,

Firstly, thanks a lot for your reply.

So for AddLineLayer, since SetXdata() is not explicitly used the XY co-ordinates are picked from Y array and indices of Xarray (same X array used for setting labels)?


About Scatter Plots, I have to correct something here. I have attached a copy of my current graph. I want to add Crosses at the parts that are colored in Circle.

The X axis is plotted with respect to time domain.
Sample Code for that:
  c.xAxis().setLabelFormat("{value|hh:nn:ss}");
LineLayer layer1 = c.addLineLayer(Y1, current_color, "ID:" +Convert.ToString(i));
layer1.setLineWidth(2);
c.xAxis().setLabels(X2);
c.xAxis().setLabelStep(25, 1);

I assume, the Array indices used to plot X co-orindate points would come from Array X2?

So, for scatter plot I have a very small array of 4 points with time an value
{(T1, -110),(T2, -100),(T3, -118),(T4, -120)}.

I am using AddScatterLayer with Xpoints being t1 through t4 and Y points as shown above. However, all the scatter points end up appearing on the right most side of the X axis. Am i doing/assuming something wrong here.

Many Thanks.
Sample_Graph.png

  Re: Markers with Scatter Plots
Posted by Peter Kwan on Mar-02-2011 00:25
Hi Viks30,

For your case, the y-coordinates are the data values in your y-array, and the x-coordinates are the index of your y-array, which is 0, 1, 2, 3, ..... Because the array index of any array is the same (they are always 0, 1, 2, 3, .....), so you can get the index from any array. It does not matter.

Suppose you want to add a scatter point at a position that corresponds to the x-axis label myTime. First, please determine the array index of myTime. For example (in C#):

int theIndexOfMyTime = Array.IndexOf(X2, myTime);

Then you can add the scatter point using that index as the x-coordinate.

c.addScatterLayer(new double[] {theIndexOfMyTime}, new double[] {Y1[theIndexOfMyTime]}, ....);

Hope this can help.

Regards
Peter Kwan

  Re: Markers with Scatter Plots
Posted by Viks30 on Mar-02-2011 07:34
Peter,

So, index numbers of X values need to be sent in the scatter plot.
However, i think I am in a unique situation here.

The linelayers that are displayed based on a XY combination like for eg:
{
(T1,Y1),(T4,Y2),(T5,Y3),(T6,Y4),(T12,Y5),(T15,Y6),(T16,Y7);
}
So X-Array is T1,T4,T5,T6,T12,T15,T16


For the scatter points, they are coming from another array where the X values( Timestamp) will not exactly match with the values from the above X-Array.

My Scatter_X-Array = T3, T11, T14.

Would this entail me to find the Closest match to each Scatter_XArray value in the X-Array above and store those index numbers. Is there a simpler way to get around the problem.

Thanks again.


Peter Kwan wrote:

Hi Viks30,

For your case, the y-coordinates are the data values in your y-array, and the x-coordinates are the index of your y-array, which is 0, 1, 2, 3, ..... Because the array index of any array is the same (they are always 0, 1, 2, 3, .....), so you can get the index from any array. It does not matter.

Suppose you want to add a scatter point at a position that corresponds to the x-axis label myTime. First, please determine the array index of myTime. For example (in C#):

int theIndexOfMyTime = Array.IndexOf(X2, myTime);

Then you can add the scatter point using that index as the x-coordinate.

c.addScatterLayer(new double[] {theIndexOfMyTime}, new double[] {Y1[theIndexOfMyTime]}, ....);

Hope this can help.

Regards
Peter Kwan

  Re: Markers with Scatter Plots
Posted by Peter Kwan on Mar-02-2011 15:21
Hi Viks30,

I think using x-coordinates for the data points (instead of setting the x-axis labels) should better match the structure of your chart. It should be like:

LineLayer layer1 = c.addLineLayer(Y1, current_color, "ID:" +Convert.ToString(i));
layer1.setLineWidth(2);
layer1.setXData(X2);  //assume X2 is an array of DateTime

c.addScatterLayer(Chart.CTime(arrayOfDateTime), arrayOfDouble, ....);

Hope this can help.

Regards
Peter Kwan