ExpertPDF Components: .NET Chart Control

WebChart Chart Labels

Learn how you can change the settings of the chart X Axis and Legend Labels.

Chart Labels

ExpertChart control offers the possibility to customize the labels that are displayed on the X Axis and also the labels displayed in the legend. By default, the first string column in the data source is the column that will be the source of the X Axis Labels. This can be changed. Also, the labels can be loaded from an array. Same for the legend labels, ExpertChart can load them from an array.

100 100 200 200 110 170 300 140 290 100 60 100 300 160 120 200 120 190 For more information visit www.chartingcontrol.net

Source code

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebChart1.DataSource = ExpertChart.Demo.DataSources.GetTestData2();
            WebChart1.LegendBox.Visible = true;
 
            // load X Axis labels from an array
            WebChart1.Labels.XAxisLabelsFromArray(new string[] { "Label 1", "Label 2", "Label 3", "Label 4", "Label 5", "Label 6" });
            
            /* // alternative method
            WebChart1.Labels.XAxisLabels.Clear();
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 1"));
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 2"));
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 3"));
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 4"));
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 5"));
            WebChart1.Labels.XAxisLabels.Add(new ExpertChart.LabelItem("Label 6"));
            */
             
            // load legend labels from an array
            WebChart1.Labels.LegendLabelsFromArray(new string[] { "Legend label 1", "Legend label 2", "Legend label 3" });
 
            /* // alternative method
            WebChart1.Labels.LegendLabels.Clear();
            WebChart1.Labels.LegendLabels.Add(new ExpertChart.LabelItem("Legend label 1"));
            WebChart1.Labels.LegendLabels.Add(new ExpertChart.LabelItem("Legend label 2"));
            WebChart1.Labels.LegendLabels.Add(new ExpertChart.LabelItem("Legend label 3"));
            */
 
            // change the default X Axis Labels database column
            //WebChart1.Labels.XAxisLabelsColumn = 1;
        }
    }

Copyright 2008. ExpertComponents.com ChartingControl.NET.