How can I change the Axis Labels in code

Posted by: kukemaster on 8 September 2017, 2:58 pm EST

  • Posted 8 September 2017, 2:58 pm EST

    I select a cell range then insert a chart in spread, but the Axis labels is auto generate as 0, 50, 100 150...., I want to change the labels to Level_1, Level_2, Level_3, Level_4...., How can do this is code.

  • Replied 8 September 2017, 2:58 pm EST

    Hello,

    You can change the axis label using the CategoryNames property of the series. Please refer to the following link that explains the same:

                    http://www.gcpowertools.com/help/spreadnet6/WF2/FarPoint.Win.Chart~FarPoint.Win.Chart.YSeries~CategoryNames.html

    Hope it will help. Please let me know if I missed something or if you have any queries further.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:58 pm EST

    Thanks


     But my code no working. Can you debug for me?


     


    2012/07/Chart.zip
  • Replied 8 September 2017, 2:58 pm EST

    kkmaster,

    The YPlotArea pulls the category names from the first series in the plot area. If the first series in the plot area is a grouped series (i.e. stacked or clustered) then the category names are pulled from the first individual series in the group. This is similar to how Excel works. You will need to assign the category names to the individual series in the group. In your example, the category names are bound to cells. You will need to unbound the category names before assigning the manual values. For example...

    foreach (StackedBarSeries group in chart.Model.PlotAreas[0].Series)
    {
        foreach (BarSeries series in group.Series)
        {
            series.CategoryNames.DataSource = null;
            series.CategoryNames.AddRange(new string[] { "AAA", "BBB", "CCC", "DDD", "EEE" });
        }
    }

Need extra support?

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

Learn More

Forum Channels