creating a custom label for axis y in ASP.Net char

2020-04-10 03:27发布

问题:

I have a 3 point axis for axisY in a chart for ASP.NET. Right now it shows 1, 2, and 3. I need to assign string values to the points. I have found that it is somewhere in here:

Chart1.ChartAreas[0].AxisY.CustomLabels.Add(??????);

Not sure how to get it not to have to take a double value and be able to assign a string to the point.

回答1:

You have to create a custom label, set its properties, then add it to the axis

What about this?

    CustomLabel label = new CustomLabel();

    label.FromPosition = -1.0;
    label.ToPosition = 1.0;
    label.Text = "0";
    label.RowIndex = 0;

    Chart1.ChartAreas[0].AxisY.CustomLabels.Clear();
    Chart1.ChartAreas[0].AxisY.CustomLabels.Add(label);

This will render a 0 where the Y-axis meets the X-axis.



标签: c# asp.net