 ChartDirector Support Forum Home Search Scatter Chart X-Axis values as text instead of double
Posted by jhow on Sep-02-2021 02:16
Attachments:
Is there a way to create a scatter chart that uses text values on the x axis instead of doubles?

I need to plot multiple values for an item under one label. There will be a different quantity of values plotted for each item and can vary from 0 to 50+.

For example:  Re: Scatter Chart X-Axis values as text instead of double
Posted by Peter Kwan on Sep-02-2021 18:57
Hi jhow,

You can put labels on the x-axis, and align the points with the labels. The points will still be using numbers as coordinates.

If the x-axis is a label based axis, the coordinate x = 0 will correspond to the first tick position (the first vertical grid line), the x = 1 will be the second tick position, and so on. You can use x = 0.5 to put a data point in between two ticks.

For your case, the labels are in between the grid lines, so the x-coordinates of the seven symbols in the chart can be { 0.5, 1.5, 1.5, 1.5, 2.5, 3.5, 3.5 }.

The following is one of the methods produce your chart (in C#):

... create chart object and set plot area size as usual ...

// 5 labels for 5 tick positions (the last label is not used in this chart)
string[] labels = { "Item1", "Item2", "Item3", "item4", "" };
c.xAxis().setLabels(labels);

// Shift the labels by 0.5 unit so that they are in between two ticks. The last label will
// be shifted out of the chart.
c.xAxis().setLabelOffset(0.5);

double[] x = { 0.5, 1.5, 1.5, 1.5, 2.5, 3.5, 3.5 };
double[] y = { ..... your y data values .....};

// Add the data points to the chart as a scatter layer
c.addScatterLayer(x, y, "", Chart.TriangleShape, 15, 0xff6600);

... output the chart ....

Hope this can help.

Regards
Peter Kwan