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

Message ListMessage List     Post MessagePost Message

  X Coordinate from Array Index
Posted by Jeff on Nov-23-2016 00:22
Is it possible to get the X coordinate of a data point on a chart from the array index? Let's say you have a linelayer and want to know the x coordinate of the 3rd data point on the chart. Is there a way to do this without using the x value itself, just array index?

Thanks,

Jeff

  Re: X Coordinate from Array Index
Posted by Administrator on Nov-29-2016 03:30
Hi Jeff,

Sorry for the late reply.

As all the x-coordinates of the data points are passed from your code to ChartDirector, so your code should already the x data array, so your code can freely get any x data value you like using the array index without involving ChartDirector.

If you are using ChartDirector for a web application, and you would to obtain the x data value by index on the browser side, you may need to pass your data array to the browser side as a Javascript array.

In general, ChartDirector is not designed as a data storage library, and it may not store your data or keep track of your data. After plotting the chart, it may remove the data it does not need to save memory, so it may no longer know all their data values or their indexes.

For example, if you are plotting a line chart with 100000 data values on a chart 500 pixels wide, after plotting the chart, ChartDirector may only keep around 500 values for the purpose of supporting programmable track cursors. It is because there can only be 500 mouse coordinates, so it is wasteful to store all 100000 data values and/or send all 100000 data values to the browser. The APIs for programmable track cursors can be used to access the values kept by ChartDirector, but they are accessed by pixel coordinates, rather than the array index.

Regards
Peter Kwan

  Re: X Coordinate from Array Index
Posted by Jeff on Nov-29-2016 08:57
Peter,

I would like to be able to draw on top of a chart and know where the data points are located; the x,y pixel coordinates of each datapoint

If you make a simple line chart, creating a line layer using;

double[] data = {30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 91, 60, 55, 53, 35, 50, 66, 56, 48, 52, 65, 62};

String[] labels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"};

like in javademo/simpleline.java;

How do I get the x,y pixel location of a specific point in this case?

Thanks,

Jeff

  Re: X Coordinate from Array Index
Posted by Administrator on Nov-29-2016 15:56
Hi Jeff,

You can get the x/y pixel position after layout (calling BaseChart.layout) or after making the chart or setting the chart to the chart viewer, by using the XYChart.getXCoor and XYChart.getYCoor.

For the "javademo/simpleline.java", it is using a label based x-axis, in which case the x-coordinate is just the array index. For example:

.... create chart as usual but just before calling viewer.setChart(c);, insert the code below .....

c.layout();

int[] xPixelCoors = new int[data.length];
int[] yPixelCoors = new int[data.length];

for (int i = 0; i < data.length; ++i) {
    xPixelCoors[i] = c.getXCoor(i);
    yPixelCoors[i] = c.getYCoor(data[i]);
}

Hope this can help.

Regards
Peter Kwan