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

Message ListMessage List     Post MessagePost Message

  Negative values in Line Chart X-axis
Posted by abhishek.mr on May-02-2018 23:12
Attachments:
Hello,

In my chart, i have x-axis value which start from Negative (like below ). But in the Chart it is appeared as positive value. Is that expected? or is there any other way to assign negative values to chart axis?

// The labels for the line chart
            string[] labels = {"-10", "-5", "-2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"};

Negative values are not appearing in x- axis . Is there any solution to fix it?


Regards,
Abhishek
Capture.PNG

  Re: Negative values in Line Chart X-axis
Posted by abhishek.mr on May-03-2018 00:27
Hello,

By adding the xAxis().SetLinearScale() works of negative value, but the yAxis Dataset values are not properly sync with X-Axis. Below is my code sample x-axis() and y-Axis data.

//scale (lowerlimit -10, upperLimit 110)
_XYChart.xAxis().setLinearScale((double)lowerLimit, (double)upperLimit);

  // Add a title to the x axis
_XYChart.xAxis().setTitle(_viewModel.HorizontalAxis.AxisLabel, "Arial", 11);

---------------------------------------------------------
Y-Axis
---------------------------------------------------------

   double[] dataSet = new double[waveForm.XyDataPoints.Count()];

            foreach (var dataPoint in waveForm.XyDataPoints)
            {
                if (dataPoint == null)
                {
                    continue;
                }

                dataSet[i] = i + 10;

                i++;
            }

            LineLayer layer = _XYChart.addLineLayer();

            // Set the default line width to 2 pixels
            layer.setLineWidth(2);


            int foreColor = 1;
            if (waveForm.LineColor != null)
            {
                string rgbColor = waveForm.LineColor.Value.R.ToString("X2") + waveForm.LineColor.Value.G.ToString("X2") + waveForm.LineColor.Value.B.ToString("X2");
                foreColor = int.Parse(rgbColor, NumberStyles.HexNumber);
            }

            layer.addDataSet(dataSet, foreColor, waveForm.Name);

            // Add a title to the y axis
            _XYChart.yAxis().setTitle(waveForm.VerticalAxis.AxisLabel, "Arial", 9);


Please let me know if I miss something to configure. Thanks in advance.

Regards,
Abhishek

  Re: Negative values in Line Chart X-axis
Posted by Peter Kwan on May-03-2018 01:48
Hi abhishek.mr,

If you use text strings, like:

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

The above are just considered as names and are just for human reading. They have no meaning to the computer and are just displayed equally spaced as is on the chart.

For labels, certain leading character can have special meaning. The "-" character means a "minor tick" (you can see the "tick" associated with the label is slightly shorter). If you want to display "-", you would need to escape it with a backslash. In C# in source, a backslash must be entered as two backslashes "\\". So in source code, the label "-5" would need to be "\\-5".

As the labels have no meaning, the data points are just plotted one by one to match the labels.

If you use Axis.setLinearScale, the x-value will be used to position the points. For example, position between -10 and -5 will be greater than the position between -5 and -2. When you add the data points, the code should specify both the x and y coordinates. If the x-coordinates are not specified, ChartDirector will just use 0, 1, 2, 3, ... (the array index) as the x-coordinates.

For your case, in addition to:

dataSet[i] = i + 10;

you may add:

xCoor[i] = x_coordinate_of_the_point;

Then the LineLayer should be added as:

LineLayer layer = _XYChart.addLineLayer();
layer.setXData(xCoor);
layer.addDataSet(dataSet, foreColor, waveForm.Name);

Hope this can help.

Regards
Peter Kwan

  Re: Negative values in Line Chart X-axis
Posted by abhishek.mr on May-04-2018 00:42
Thanks Peter for the solution. It works fine for me.

Regards,
Abhishek.