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

Message ListMessage List     Post MessagePost Message

  Y Labels not display with the data
Posted by Blair on Apr-11-2017 22:24
When I add a set of labels to the y axis the data disappears.  I have cut/pasted the code from the simple line chart and added  the y labels that have really no reference to the data.... suggestions?

      protected void Page_Init(object sender, EventArgs e)
        {
            WebChartViewer.OnPageInit(this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            //Draw the graphs
            Table tbl = new Table();
            TableRow tblr1;
            TableCell tblc1;

            lblTtitle.Text = "Plot Data";
            tblr1 = new TableRow();
            tblc1 = new TableCell();
            tblc1.Controls.Add(GraphCokePyroTemperatures3());
            tblr1.Controls.Add(tblc1);
            tbl.Controls.Add(tblr1);

            tbl.GridLines = GridLines.Both;
            idCharts.Controls.Add(tbl);
        }

        protected Control GraphCokePyroTemperatures3()
        {
            // The data for the line chart
            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[] yLabels =
            {
                "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"
            };

            // The labels for the line chart
            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" };

            XYChart c = new XYChart(250, 250);
            c.setPlotArea(30, 20, 200, 200);
            c.addLineLayer(data);

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Set the labels on the y axis.
            c.yAxis().setLabels(yLabels);

            c.xAxis().setLabelStep(3);

            // Output the chart
            WebChartViewer wcvGraph = new WebChartViewer
            {
                Image = c.makeWebImage(Chart.PNG),
                ID = Guid.NewGuid().ToString()
            };


            return wcvGraph;
        }

  Re: Y Labels not display with the data
Posted by Peter Kwan on Apr-12-2017 01:06
Hi Blair,

In ChartDirector, labels are just for human reading and have no meaning to the code. For example, the y-axis labels can be set as:

string[] yLabels = { "0", "1", "Apple", "429", "14", "Jan 14, 2017", "Cat" };

and ChartDirector will display the labels on the y-axis.

Because the labels has no meaning to the code, so if a label based axis is used, ChartDirector will assume the axis scale to be the array index of the labels. For example, for the above yLabels, the y-axis scale will become 0 - 6 (as the array index is from 0 to 6), and the labels will be positioned at y=0, y=1, y=2, ... y=6.

For your case, there are 25 y-axis labels. So the y-axis scale is 0 to 24. However, all the data points are greater than 24. So no data points are within the y-axis range and the line is outside the chart.

Would you mind to clarify what do you expect the chart to display?

Regards
Peter Kwan

  Re: Y Labels not display with the data
Posted by Blair on Apr-12-2017 01:18
I am expecting the labels to over lay where ever the y-axis ends up.  So if there are 25 y data points with 25 y data labels, they would all get put together on the chart.

I didn't realize the label array index was going to be used as a data point on the y axis, that makes aligning the labels with the data a little difficult.
Thanks for the response.
Blair

  Re: Y Labels not display with the data
Posted by Peter Kwan on Apr-12-2017 04:18
Hi Blair,

The actual data in this example is from 30 to 91. To display the line, the y-axis scale must include this range.

If you have a y-axis scale you want to use, and you want to spread the labels along the scale, you can use Axis.setLinearScale2. For example:

// Use the y-axis scale 0 to 100, and spread the labels evenly on the y-axis
c.yAxis().setLinearScale2(0, 100, yLabels);

If you just want evenly spaced numbers reflecting the axis scale on the y-axis (eg. like 0, 20, 40, 60, 80, 100), you can use setLinearScale:

// Use the y-axis scale 0 to 100, and add a label every 20 units
c.yAxis().setLinearScale(0, 100, 20);

If you want to let ChartDirector automatically determine the axis scale, and you want to spread the labels evenly on the axis scale, that means the labels are unrelated to the axis scale. (The labels are always the same regardless of the of what is the axis scale.) In this case, you can add an extra y-axis on the left side (therefore overlapping with the original y-axis), add the labels to that extra y-axis, and configure the label colors of the original y-axis to transparent (using Axis.setLabelStyle). In this way, what is visible are you labels, but the line is using the scale of the invisible y-axis. The Muitiple Axes sample code demonstrates how to add extra axes:

http://www.advsofteng.com/doc/cdnet.htm#multiaxes.htm

Regards
Peter Kwan

  Re: Y Labels not display with the data
Posted by Blair on Apr-12-2017 20:42
Thanks Peter, I believe I can work with that solution.
Blair