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

Message ListMessage List     Post MessagePost Message

  adding a line on the chart....
Posted by Ramesh on Nov-02-2011 15:25
Hi,

I have a chart with x-axis with 10 labels. I need to add line layer on the chart with
different set of x-axis data, not with the data on the x-axis, is it possible?

Right now, its working with same set of x-axis data.
Below is the code.

Line1 = Thechart.addLineLayer(Data1,Chart. Transparent);
Line2 = Thechart.addLineLayer(Data2,Chart. Transparent);

Line1.setXData(xData1);
Line2.setXData(xData2);

Where xData1 and xData2 is different from x-axis data. how to make it possible. x-axis data
is string data and setXData expects double data.


Thanks
Ramesh

  Re: adding a line on the chart....
Posted by rafal_rr on Nov-02-2011 20:53
I don't know that I understood your problem but I had a similar problem: I needed draw 2
functions on one chart:
f1(x) for x in <-1; 1>
f2(x) for x in <0; 2>

So I've created labels for x in <-1; 2> and 2 vectors with data:
v1 = f1(x) for x in <-1; 1> and NaN for x in (1; 2>
v2 = NaN for x in <-1; 0) and f2(x) for x in <0; 2>

I've used std::numeric_limits<double>::quietNan() as NaN.

  Re: adding a line on the chart....
Posted by Ramesh on Nov-02-2011 21:02
what does Line.setXData() method do?
Based on the X axis data, LineLayer is plotted across the chart, right?

Ramesh

  Re: adding a line on the chart....
Posted by Peter Kwan on Nov-02-2011 22:30
Hi Ramesh,

In Layer.setXData, the x-data determines the position of the data points. For example, suppose the x-data are {0, 1, 3.5, 4}. It means the x-spacing for the first two points (0, 1) are 1 unit, and for next two points (1, 3.5) are 2.5 units, and for the last two points (3.5, 4) are 0.5 units.

You mentioned you are using "labels" on the x-axis. Do you mean you are using a label based x-axis set up using Axis.setLabels or Axis.setLabels2? Suppose you use the labels {"Red", "Green", "Blue", "Yellow", "Pink"} on the x-axis. There is no standard rule on how to put the data points at {0, 1, 3.5, 4} on the axis with labels {"Red", "Green", "Blue", "Yellow", "Pink"}. In ChartDirector, the rule for label based x-axis is that the x-coordinate {0, 1, 3.5, 4} will be interpreted as the array index of the label. So x = 0 will be put on the first label "Red". x = 1 will be on the second label "Green". x = 3.5 will be in the middle between the 4th label "Yellow" and the 5th label "Pink".

If you do not use Axis.setLabels or Axis.setLabels2 to configure the x-axis, ChartDirector will auto-scale the x-axis, just like how it auto-scales the y-axis. ChartDirector will automatically put the labels on the x-axis. Just like the case of the y-axis, the x-axis range will include your data range, but the x-axis labels may not be the same as your data. For example, if your x-data are {0.123538, 1.21412, 1.55421, 1.9124, 3.1247, 3.9872}, ChartDirector may use {0, 1, 2, 3, 4} as the x-axis label.

In addition to use Axis.setLabels, you may also configure the x-axis using Axis.setLinearScale, Axis.setLinaarScale2, Axis.setLogScale, Axis.setDateScale, .... In these cases, the x-axis is not regarded as a label based axis, but as a numeric or date/time axis. Again, just like the y-axis, the labels on the x-axis do not need to be the same as the data values.

Hope this can help.

Regards
Peter Kwan

  Re: adding a line on the chart....
Posted by Ramesh on Nov-03-2011 00:10
Hi Peter,
I think i'm not clear in explaining my problem

I have data like this

Timestamp             StringData     SomeValue
11/1/2011 7:00        String1            10

11/1/2011 8:00        String2             9

11/1/2011 9:00        String3            11

11/1/2011 10:00      String4              8

11/1/2011 11:00      String5             12

on the chart, i'll show the StringData on x-axis as lables using

"chart.xAxis().setDateScale(0, labels.Length - 1, labels);"
where the labels are stringData. and the "SomeValue" is the actual line on the chart

Now,  i have one more set of data based on timestamp, like this.


Start Timestamp   End Time                    SomeData
11/1/2011 7:00        11/1/2011 9:00           10.5

11/1/2011 9:00        11/1/2011 11:00          11.5


Now, i need show the "SomeData" on the above chart through all the chart.

If i have timestamp as x-axis lables i could show the line using the below code.
Line1 = TheChart.addLineLayer(SomeData, Chart.Transparent);
Line1.setXData(timestamps); where timestamps are converted to double.

How do i do that if i have string data on x-axis as labels ?
Am i clear?


Thanks
Ramesh

  Re: adding a line on the chart....
Posted by Peter Kwan on Nov-03-2011 01:00
Hi Ramesh,

With your current code "chart.xAxis().setDateScale(0, labels.Length - 1, labels);", the first label position is x = 0, the second label position is x = 1, and so on.

So if you have something that is from "11/1/2011 7:00 to 11/1/2011 9:00", the x-coordinates will be from x = 0 to 2. (11/1/2011 7:00 corresponds to String1 in your x-axis, which is the first label x = 0. 11/1/2011 9:00 corresponds to String3 in your x-axis, which is the third label x = 2.)

Note that in your current code "chart.xAxis().setDateScale(0, labels.Length - 1, labels);", the timestamps are never passed to ChartDirector, so ChartDirector does not know about your timestamps. If your timestamps are evenly spaced, you may also use:

chart.xAxis().setDateScale(startTime, endTime, labels);

In the above, startTime is the java.util.Date object (in Java) or DateTime object (in C#), which represents the timestamp at the first label (11/1/2011 7:00 in your example). The endTime represents the timestamp at the last label (11/1/2011 11:00 in your example). With the above code, when you use setXData, you can use the timestamps directly as the x-coordinates, because ChartDirector now knows that the labels represent the time range from startTime to endTime.

Hope this can help.

Regards
Peter Kwan

  Re: adding a line on the chart....
Posted by Ramesh on Nov-03-2011 02:23
Hi peter,

Thanks for the reply.  That makes sense. But, when i specify the lowerlimit and upper limit like this _chart.xAxis().setDateScale(lowTimestampVal, highTimestampVal, labels);
i don't see the data being plotted on the chart, Linelayer is added successfully though.
what could be the reasone.

Thanks.
Ramesh.

  Re: adding a line on the chart....
Posted by Ramesh on Nov-03-2011 02:59
Hi Peter,

I figured out the issue. You solved my problem. Thanks alot!!!
You helped me always!!

Thanks,
Ramesh.

  Re: adding a line on the chart....
Posted by Ramesh on Nov-03-2011 22:06
Hi Peter,

      Now i see a different behavior on the chart when i specify timestamp on x-axis using the method setdatascale(lowtimestamp,hightimestamp, labels).
  Chart was showing correct sometimes, showing wrong some times. attached chart image FYI.

Thanks
Ramesh

  Re: adding a line on the chart....
Posted by Ramesh on Nov-03-2011 22:35
Attachments:
I think i missed attachment.. here it is.
chart.JPG

  Re: adding a line on the chart....
Posted by Peter Kwan on Nov-03-2011 23:59
Hi Ramesh,

I see the attached chart now. However, I do not know what is the issue. Would you mind to clarify what is the issue on the attached chart?

If you use "setdatascale(lowtimestamp, hightimestamp, labels)", you can and must use setXData on all your layers (including the line layer) to specify the x-coordinates of your data points. I assume you have already done that (otherwise you would not see the line at all).

If you think the data points are not at the correct position, would you mind to include a chart with the x-axis visible (so I can see if the data points are at the correct position)? Also, when creating the chart, please include the following code:

c.addTitle("" + lowtimestamp.ToString() + ", " + hightimestamp.ToString());
myLineLayer.setDataLabelFormat("{x}");

The above allows the date range and the x-coordinates to be visible on the chart. This can help to determine if the data points are in the correct position.

Regards
Peter Kwan

  Re: adding a line on the chart....
Posted by Ramesh on Nov-04-2011 01:01
Hi Peter,

The problem is data is not scatterd across the chart based on the x-axis labels. It is plotting all the data at one place. What could be the reason doing like this. will send you the screen shot in a moment.

Thanks
Ramesh

  Re: adding a line on the chart....
Posted by Ramesh on Nov-04-2011 01:24
Attachments:
Hi Peter,

Attached 2 images, one is in good shape and the other is bad shape. I see the issue when i redraw the chart second time or when i have points more that 15 on the chart.

please help me.

Ramesh
good chart.JPG
badchart.JPG

  Re: adding a line on the chart....
Posted by Peter Kwan on Nov-04-2011 17:54
Hi Ramesh,

Based on your screen, I think the charts plotted by ChartDirector correctly reflects your data. The data are plotted "all in one place", because  your data are really "all in one place" according to your chart configuration.

For example, consider the chart in which the data points are all on the right side. Your code have configured the x-axis scale to be "5/13/2008 10:54:00 pm" to "5/15/2008 12:42:00 am". The first point of your line is at "5/14/2008 20:00:00", so it is normal the first point is near the right side of the x-axis.

If the above is not what you expect, is it possible your code has set the x-axis scale incorrect, or the x-coordinates you are using are incorrect?

Regards
Peter Kwan

  Re: adding a line on the chart....
Posted by Ramesh on Nov-04-2011 20:48
Attachments:
Hi Peter,

Yes, i think its because of the time stamps i see the chart behavior different. However, i need to plot points on the chart based on the labels, is it possible?
So, here there are 2 things

1. Plot points based on the labels where labels are strings
2. Add a line to the chart based on the x-axis data using SetXData().

is it possible ?

If you see in the attachment, there are 2 different line layers. One with set of colours and the other actual line with points plotted.

Colorful line layers are based on the timestamps and the points line layer is also on the time stamps, However, if we want to show string data on the x-axis as labels, each point is associated with each string on the x-axis, but the colorful line layers are based on the time stamps. If i add time stamps to x-axis using SetXData() and scaleDataLine(lowerlimitdate,higlimitdate,labels) its actually changing the expected behavior but it is correct as per chart director.

I think i need to group the strings based on the timestamps and set these groups using setXData().

Is there anyway, we can have a line layer based on the timestamps but not x-axis data.


Thanks
Ramesh
colorfulchart.JPG

  Re: adding a line on the chart....
Posted by Peter Kwan on Nov-05-2011 00:56
Hi Ramesh,

For your specific chart, please note that the horizontal lines do not need to be added as line layers. You can add them as marks and zones. (See the "Marks and Zones" sample code included in ChartDirector.) With marks and zones, you do not need to use x-coordinates at all. (ChartDirector just draws a horizontal line from the left to right.)

In your last case, the data points are crowded to the right of the chart, because the x-coordinates you use are crowded to the right of the chart. For example, the lowerlimitdate in your x-axis scale is set as 5/13/2008 10:54:00am, but the first data point of your line is set at 5/14/2008 10:00:00pm. If you would like the data point to start from the left edge of the chart, please use 5/14/2008 10:00:00pm as the lowerlimitdate in your x-axis scale, or modify the x-coordinates of your data points so that the data starts at the lowerlimitdate 5/13/2008 10:54:00am.

As an example:

chart.xAxis().setDateScale(startTime, endTime, labels);
LineLayer layer = c.addLineLayer(myData);
//make sure the line uses x-coordinates that is consistent with the x-axis
layer.setXData(startTime, endTime);

If you would like to use both labels on the x-axis, and timestamps as the x-coordinates, there must be a mapping that converts the labels to the timestamps. For example, suppose your labels are {"Apple", "Orange", "Pear"}, and you want to plot a point at x = "10/3/2011 11:00am", there is no way to know where is the point given the 3 labels {"Apple", "Orange", "Pear"} unless the labels can be converted to timestamps.

In ChartDirector, the method that converts the labels to the timestamps is setDateScale(startTime, endTime, labels), which you are already using. With the method, for your first line, you need to inform ChartDirector where are the points in terms of timestamps. If you are using labels, you can convert the "labels" to the timestamps before passing them to ChartDirector. If the line is not at the expected position, it is likely the conversion code is incorrect.

Anyway, as explained above, if all you need is to draw additional horizontal lines, you would not need to use timestamps at all, as you can use marks and zones.

Hope this can help.

Regards
Peter Kwan