Change the Y axis units

Originally Posted 7 July 2013, 4:06 am EST

  • Originally Posted 7 July 2013, 4:06 am EST


    I have a bar chart which display value of sales in millions $. Is there a way to change the labels on the Y axis that they will be displayed as the real value divided by 1000?
    Instead of values from 0 to 10,000,000 in jumps of 1 million the labels will be from 0 to 10,000.
    I can not use valueLabels because I do not know the range of the values. The maximum value can be 20 millions as well.
    I do not want to change the original data source because I want the tooltip to show the real value (See attached example).

    Is there a way to calculate the valueLabels when the chart is rendered or an event that I can change the Y axis labels there?


  • Reply

    Hello Guy-G,

    To achieve your requirement, you'd have to calculate the max value from the datasource and set it as the Max of Y Axis. Once, you've calculated the Max, you can add value labels to list of ValueLabel and set it to the ValueLabelList property of Y Axis in the following way :

    for (int i = 0; i < yValues.Length; i++)
    if (yValues[i] > maxValue)
    maxValue = yValues[i];

    for (int j = 0; j <= maxValue; j += 1000000)
    valueLabellist.Add(new ValueLabel() { Text = (j / 1000).ToString() });

    ChartAxis yAxis = C1BarChart1.Axis.Y;
    yAxis.AnnoMethod = ChartAxisAnnoMethod.ValueLabels;
    yAxis.Text = "Total Sales (x1000)";
    yAxis.AutoMin = false;
    yAxis.AutoMax = false;
    yAxis.AutoMajor = false;
    yAxis.UnitMajor = 1000000;
    yAxis.Max = maxValue;
    yAxis.Min = 0;

    I've attached a sample with the above implementation along with. Please let me know if you need any other help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels