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

Message ListMessage List     Post MessagePost Message

  Plot the Y values on specified X axis points.
Posted by Vishruth HV on Apr-22-2019 22:30
Attachments:
Hello team,

I need to plot the 4 to 5 different values with different annotations ( Triangular , Square ) on the chart. I need to plot the different values for different X axis values. Multiple values cannot be plotted for same point.
For example : I have numbers 30 to 50 as my X Values. Also, I have multiple Y values. I need to plot the value Y on x-30 and next value of Y on x-32. Basically, the requirement is Y values should be plotted at the fixed point of X and not sequentially.
When am adding the data to the collection, I should be adding both X and Y Values so that data is plotted exactly at point required.

Is there any collection where both X and Y values can be added to the collection ?

Please let me know how to fix the Y axis range to specific values ??

Added the sample image for your reference.

Regards,
Vishruth
ChartDirectorImage.png

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on Apr-23-2019 13:35
Hi Vishruth HV,

Is the scatter chart what you need? See:

https://www.advsofteng.com/doc/cdcpp.htm#scatter.htm

You can specify the x and y coordinates of individual points, and you can use multiple layers, one for each symbol shape.

By default, ChartDirector will automatically configure the axis scale based on your data values. However, if you want to specify the scale with your own code, you can use Axis.setLinearScale. For example, in C++, it is like:

// From -8 to 8, with a label every 2 units.
c->yAxis()->setLinearScale(-8, 8, 2);

If you need further help, please let me know of your programming langauge.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth HV on Apr-23-2019 15:05
Hi Peter,

Thanks. Programming language is C#.

Can you please share sample code on how to set the XY Coordinates for individual points.

Regards,
Vishruth

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on Apr-24-2019 00:07
Hi Vishruth HV,

Here is the C# version of the sample code that uses individual x and y coordinates for the data points.

https://www.advsofteng.com/doc/cdnet.htm#scatter.htm

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth HV on Apr-25-2019 13:12
Thanks Peter.

That works. I need help for below queries.

1. I need to hide both Vertical and Horizontal lines in the chart. I would like to draw only 1 horizontal line for point 0,0 as seen in the above image.

2. I need to add some space before starting and at the end of the chart for X and Y Coordinates as seen in the above image.

3. Am adding external images for the X Data points. I need to minimize and maximize the size of the images based on the required. Am not getting the API for that.


It would be good if you assist with the source code for above queries. Programming language is C#.

Thanks again.


Regards,
Vishruth

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on Apr-25-2019 16:44
Hi Vishruth,

1. When your code call XYChart.setPlotArea, it can set the horizontal and vertical grid line colors to transparent. See:

https://www.advsofteng.com/doc/cdnet.htm#XYChart.setPlotArea.htm

For example:

c.setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, Chart.Transparent, Chart.Transparent);

After removing all the grid lines, you can add the y = 0 grid line back using Axis.addMark. See:

https://www.advsofteng.com/doc/cdnet.htm#Axis.addMark.htm

For example:

c.yAxis().addMark(0, 0xcccccc);


2. Depending on exact what you want, there are several methods to add space around the border of the plot area:

(a) Use Axis.setIndent. This will add 0.5 units to the end points of the axis. This is most useful if the data points are at integral (x, y) values. For example:

// extend scale by 0.5 units
c.xAxis().setIndent(true);

(b) Use Axis.setMargin. This will add a number of pixels at the end point of the axis. For example:

// 15 pixels margin at either end points
c.xAxis().setMargin(15, 15);

(c) Use Axis.setAutoScale. This will extend the axis scale to ensure at least some percentage at the axis end points have no data. This only applies if the axis is auto-scaled by ChartDirector. For example:

// Extend axis scale so that at least 5% empty space at either end points.
c.xAxis().setAutoScale(0.05, 0.05, 0);

By deafault, ChartDirector will extend the scale at the next labelled position. For example, it may extend the scale from (5, 6, 7, 8, 9) to (4, 5, 6, 7, 8, 9, 10), but not to (4.778, 5, 6, 7, 8, 9, 9.222) if 4.67 and 9.33 are non-labelled positions. This means the actual extension can be more than 5%. You can use Axis.setRounding to disable extending to the next labelled position like:

c.xAxis().setRounding(false, false);

In the above, the code also applies to the y-axis.

3. I am not sure what are "X" Data points. Do you mean data points ? The following is an example in which the symbol sizes are set by another array. You can see the circle symbols are of different sizes.

https://www.advsofteng.com/doc/cdnet.htm#bubble.htm

You mention the size if the "images". I assume you are referring to the square and triangle symbols. If you really mean a custom image (like a JPG file), see:

https://www.advsofteng.com/doc/cdnet.htm#scattersymbols.htm
https://www.advsofteng.com/doc/cdnet.htm#customsymbolline.htm

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth HV on Apr-25-2019 17:33
Thank you very much, Peter.

1st and 2nd answers worked.

Regarding 3rd question, am adding the external images for the data points. Since the image is very big, it is consuming more space in the chart. I want to reduce the image size so that it fits perfectly for the exact X Value.


I need the API information for above query.


Regards,
Vishruth

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on Apr-26-2019 01:27
Hi Vishruth,

If you want the image to be of a fixed size (say 16 x 16 pixels), you can use DrawArea.resize to resize it, then use the resized image as the scatter symbol. The relevant APIs are:

https://www.advsofteng.com/doc/cdnet.htm#DrawArea.load.htm
https://www.advsofteng.com/doc/cdnet.htm#DrawArea.resize.htm
https://www.advsofteng.com/doc/cdnet.htm#DataSet.setDataSymbol3.htm

It is like:

DrawArea d = new DrawArea();
d.loadPNG("/path/to/your/image.png");
d.resize(16, 16);

ScatterLayer layer = c.addScatterLayer(dataX, dataY);
layer.getDataSet(0).setDataSymbol3(d);

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on Apr-26-2019 12:58
Perfect.

Thanks. This helps a lot.

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-01-2019 17:31
Attachments:
Hi Peter,

I need to draw vertical lines for some values in the chart for specific values. I have tried using AddZone and AddMark API's. Those are not working as it would plot it for entire chart.

Please help me with API's for this requirement. Attached the image for your reference.

Please let me know if you need more information.

Thanks.

Regards,
Vishruth
ChartDirectorImage.png

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-02-2019 14:24
Hi Vishruth,

There are many methods to do what you need. For example:

(a) You can use Axis.addMark for the x-axis to add a vertical mark line. You can set the line color to a y-zone color so that the line open appears between two y-values (such as between y = -4 to y = 2). The code is like:

// Transparent below -4 and above 2. So only visible for -4 <=y <= 2.
int lineColor = c.yZoneColor(-4, Chart.Transparent, c.yZoneColor(2, 0xff0000, Chart.Transparent));

// Add the mark line at x = 30, only visible for -4 <= y <= 2.
c.xAxis().addMark(30, lineColor);

(b) Another method is to simply add a line layer with two data points for the vertical line. You can use multiple lines layers for multiple vertical lines.

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-02-2019 20:51
Hi Peter,

Thanks a lot for your help.

I tried with first approach and it worked. Now, am trying to take the image of chart in .png format. I have been using Microsoft API's. I can only see the legends and not the chart plotting area. I need to take the image of full chart.

Can you please help me with this.


Regards,
Vishruth

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-03-2019 00:07
Hi Vishruth,

You can use BaseChart.makeChart to save the chart as a PNG file. For example:

c.makeChart("c:\aaa\bbb\mychart.png");

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-03-2019 16:59
Attachments:
Hi Peter,

I tried with makechart API. But the image does not have the plotting area. I can only see the legends but the not the data being drawn in the chart. I have attached the image for your reference. Please let me know what could possible the issue.,


Regards,
Vishruth
MakechartImage.png

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-03-2019 23:12
Hi Vishruth,

One possibility is that there is no data to plot. For example, if you add scatter layers with no data (the data arrays are null or the array size is 0), there will still be legend entries, but the plot area will display nothing.

Consider the Scatter Chart sample code that comes with ChartDirector:

https://www.advsofteng.com/doc/cdnet.htm#scatter.htm

If you add the line:

c.makeChart("c:aaabbbmychart.png");

then the scatter chart will be produced as a PNG image.

However, if you set the data arrays to arrays of zero size:

dataX0 = new double[0];
dataX1 = new double[0];
dataY0 = new double[0];
dataY1 = new double[0];

then the chart image will contain the legend entries, but the plot area will contain nothing.

If you need further help, is it possible to provide an example that I can run to help me diagnose the problem? For example, you can modify the "Scatter Chart" sample code until the problem occurs, and then attach the modified code in your message.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-04-2019 17:28
Attachments:
Hi Peter,

Thanks. Issue is fixed now. Can we set in the y axis that the minor ticks are not displayed. In the attached image, I would like show just the values like 0,100,200. Values should be displayed in hundreds only. This condition should be applied only when value is beyond 100 or -100.

Regards,
Vishruth
chartImage.png

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-06-2019 15:59
Hi Vishruth,

If the y-axis scale is automatically determined by ChartDirector, you can use Axis.setMinTickInc to make sure the tick increment is at least 100.

c.yAxis().setMinTickInc(100);

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on Jun-03-2019 14:58
Hi Peter,


The above API worked perfectly to draw horizontal bars when Xaxis data and Yaxis Data is passed like below.

double[] Y = { 1, 2, 1.1, 2.1, 2.5, 1.8, 1.5 };
double[] X = { 19, 21, 23, 25, 27, 28 };
c.addScatterLayer(X1, Y1, "", Chart.SquareSymbol, 13, 0xff0000);
int lineColor = c.yZoneColor(-4, Chart.Transparent, c.yZoneColor(2, 0xff0000, Chart.Transparent));
c.xAxis().addMark(150, lineColor);
viewer.Chart = c;

Due to some requirement, I changed the implementation as below to pass the Xaxis data and Y axis data.

double[] dataX = { 140, 144, 145, 149, 150, 152, 153, 165 };
double[] dataY0 = { 130, Chart.NoValue, 80, 110, 110, 105, 130, 115 };

c.xAxis().setLabels(dataX);
c.addScatterLayer(null, dataY0, "AAA", Chart.DiamondSymbol, 13, 0xff9933);
int lineColor = c.yZoneColor(-4, Chart.Transparent, c.yZoneColor(2, 0xff0000, Chart.Transparent));
c.xAxis().addMark(150, lineColor);
viewer.Chart = c;
Now, the horizontal bar lines are not plotting in the graph.

Can you let me know what could be the issue. ?

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on Jun-03-2019 18:16
Hi Vishruth,

In your new code, the dataX are labels, not x-coordinates. (Labels are like "names". They have no meaning to the computer and is just for human reading.) There is no x-coordinate for the scatter layer (it is just set to null in your code). In this case, the x-coordinates are just the array index of your dataY0, which is 0, 1, 2, 3, ..... They are also the position where the labels (dataX) are put on the x-axis.

If you want to put a mark at the label "150", which is the 5th position in the array, the code is:

// The 5th position has array index 4.
c.xAxis().addMark(4, lineColor);

The line color is set to be non-transparent only between y=-4 and y=2. With the above code, it should be visible if your y-axis includes the range -4 to 2.

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-04-2019 23:16
Attachments:
Hi Peter,

In the attached image , 23 values are added for X axis. I have requirement that only 20 data points should be shown. Hence X axis should have only 20 values. As you can see in the image for some x values there is no data and it should be shown.

If i use the setLinearScale API , I should specify the min and max range. Instead, Can i add the values explicitly. ? I have tried the setlabels(string[]) and setlabels(double[]). Both does not work. I want to show the X Values in sequence but not the continuous values.

Let me know if you need more information.

Regards,
Vishruth
ChartDirec.png

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-06-2019 18:04
Hi Vishruth,

I am not too sure of your requirement. In your chart, you have 17 symbols from x = 130 to x = 151. The following x-values have no symbols x = 132, 136, 142, 143, 144, 152, 153.

Do you want to remove x = 152 and x = 153 only? In this case, the chart will be from x = 130 to x = 151, which has a total of 22 x-values.

Or do you want to remove x = 132, 136, 142, 143, 144, 152, 153?

If you want to show only the values with data, then the axis is not "linear". You can use Axis.setLabels instead.

double[] xLabels = {130, 131, 133, 134, 135, 137, 138, 139, 140, 141, 145, 146, 147, 148, 149, 150, 151};
double[] yData = {250, 250, 250, 250, .....};

c.xAxis().setLabels(xLabels);

// Use null for the xData array, or use {0, 1, 2, 3, .... 16} as the xData array
c.addScatterLayer(null, yData, .....);

Hope this can help.

Regards
Peter Kwan

  Re: Plot the Y values on specified X axis points.
Posted by Vishruth on May-07-2019 16:53
Hi Peter,

Is it possible to remove the values in X-axis for which there is no data points in the chart.

Regards,
Vishruth

  Re: Plot the Y values on specified X axis points.
Posted by Peter Kwan on May-07-2019 18:39
Hi Vishruth,

The code in my last message is already removing  the values in X-axis for which there is no data points in the chart. Have you tried them?

double[] xLabels = {130, 131, 133, 134, 135, 137, 138, 139, 140, 141, 145, 146, 147, 148, 149, 150, 151};
double[] yData = {250, 250, 250, 250, .....};

c.xAxis().setLabels(xLabels);

// Use null for the xData array, or use {0, 1, 2, 3, .... 16} as the xData array
c.addScatterLayer(null, yData, .....);

Regards
Peter Kwan