|
Marks and Zones for Chart |
Posted by eddy glaister on May-21-2014 23:58 |
|
Hi there,
Marks and zones are no longer working for my chart.
Previously I could add a mark / zone by using the following code:
int LinePos = 20;
Mark xMark1 = c.xAxis().addMark(LinePos, 0x995500, "my line");
However, now that I have converted my chart to allow for zoom / scrolling it has stopped
working.
Previously my x axis was defined by the following code:
// Set the labels on the x axis.
c.xAxis().setLabels(strDateTimes);
The arrDateTimes array previously contained a list of c# string values - this array was
the same size of the array of data for the chart.
Now, I don't use this method I use the following code - which passes in a DateTime
array:
layer.setXData(arrDateTimes);
I thought that this had something to do with it as when I did a wee test passing in
DateTimes in to the "addMark" method it plotted no problem. As below:
DateTime from = new DateTime(2014, 05, 19);
DateTime to = new DateTime(2014, 05, 20);
c.xAxis().addZone(Chart.CTime(from), Chart.CTime(to), 0xF8E9E9);
The question is: Can a chart with zoom + scroll work without setting the X axis as a
array of DateTimes or is this required? |
Re: Marks and Zones for Chart |
Posted by Peter Kwan on May-22-2014 06:07 |
|
Hi eddy,
If you are using setXData(arrDateTimes), then the argument to addMark should be the
DateTime itself, like:
Mark xMark1 = c.xAxis().addMark(arrDateTimes[20], 0x995500, "my line");
It is possible to perform zooming and scrolling by using Axis.setLabels (without using
setXData). However, in this case, ChartDirector will treat the labels as "names". They can
be any text and have no meaning to ChartDirector and are just for human reading.
ChartDirector cannot use the "names" to represent the axis scale, so it simply uses the
array index as the axis scale. In your original code, adding the mark at x=20 means to add
the mark at the label position at array index 20.
If you are using zooming with Axis.setLabels, initially you should set the "full range" to
represent the array index of your full data (0 to number_of_labels - 1). Then after zooming
in, you can obtain the index of the visible view port using:
// Get the array indexes that corresponds to the visible start and end dates
int startIndex = (int)Math.Floor(Chart.bSearch(timeStamps, viewPortStartDate));
int endIndex = (int)Math.Ceiling(Chart.bSearch(timeStamps, viewPortEndDate));
You would then need to obtain the data within the above range and draw the chart. Note
that there is no need to use syncDateAxisWithViewPort for the x-axis.
Hope this can help.
Regards
Peter Kwan |
Re: Marks and Zones for Chart |
Posted by Peter Kwan on May-22-2014 06:10 |
|
Hi eddy,
Sorry, I copied and pasted the wrong code. The correct code to obtain the array indexes
is:
// Get the start date and end date that are visible on the chart.
int startIndex = (int)Math.Floor(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
int endIndex = (int)Math.Ceiling(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
viewer.ViewPortWidth));
Hope this can help.
Regards
Peter Kwan |
|