Spread ASP.NET 17
Spread for ASP.NET 17 Product Documentation / Developer's Guide / Working with the Chart Control / Understanding and Customizing Charts / Labels
In This Topic
    Labels
    In This Topic

    The labels contain the plot title and the axis labels. You can set the main title for the chart using the Text property in the LabelArea class.

    You can set the text, alignment, and other formatting properties for the axis labels. You can use the IndexAxis.Title property in the plot area class to set the title for the x-axis. Whereas ValueAxis.Title property is used to set the title in the plot area for the y-axis. For more formatting, use TitleTextFill and TitleTextFont properties. You can also set the TitleOffset, if required. Here, the label text can also be bound to a datasource with the TitleDataSource and TitleDataField properties.

    For more details, refer to the following classes:

    Using Code

    The following examples show how to set axis labels in different ways.

    Example 1: Set a title and formatting for the axis labels.

    C#
    Copy Code
     // Create a plot area
     YPlotArea plotArea = new YPlotArea();
     plotArea.Location = new PointF(0.2f, 0.2f);
     plotArea.Size = new SizeF(0.6f, 0.6f);
     // Set the title and formatting in the plot area for the x-axis
     plotArea.XAxis.Title = "Categories";
     plotArea.XAxis.TitleTextFont = new System.Drawing.Font("Arial", 12);
     plotArea.XAxis.TitleTextFill = new FarPoint.Web.Chart.SolidFill(Drawing.Color.Crimson);
     plotArea.XAxis.TitleVisible = true;
     // Set the title and formatting in the plot area for the y-axis
     plotArea.YAxis[0].Title = "Values";
     plotArea.YAxes[0].TitleTextFont = new System.Drawing.Font("Comic Sans MS", 12);
     plotArea.YAxes[0].TitleTextFill = new FarPoint.Web.Chart.SolidFill(Drawing.Color.Chartreuse);
    
    VB
    Copy Code
     ' Create a plot area
     Dim plotArea As New FarPoint.Web.Chart.YPlotArea()
     plotArea.Location = New PointF(0.2F, 0.2F)
     plotArea.Size = New SizeF(0.6F, 0.6F)
     ' Set the title and formatting in the plot area for the x-axis
     plotArea.XAxis.Title = "Categories"
     plotArea.XAxis.TitleTextFont = New System.Drawing.Font("Arial", 12)
     plotArea.XAxis.TitleTextFill = New FarPoint.Web.Chart.SolidFill(Drawing.Color.Crimson)
     plotArea.XAxis.TitleVisible = True
     ' Set the title and formatting in the plot area for the y-axis
     plotArea.YAxis(0).Title = "Values"
     plotArea.YAxes(0).TitleTextFont = New System.Drawing.Font("Comic Sans MS", 12)
     plotArea.YAxes(0).TitleTextFill = New FarPoint.Web.Chart.SolidFill(Drawing.Color.Chartreuse)
    

    Example 2: Set axis labels from the DataSource.

    C#
    Copy Code
     DataTable table = new DataTable();
     DataRow dr = table.NewRow();
     table.Columns.Add("Category");
     dr[0] = "03:00-04:00";
     table.Rows.Add(dr);
     dr = table.NewRow();
     dr[0] = "04:00-05:00";
     table.Rows.Add(dr);
     dr = table.NewRow();
     dr[0] = "06:00-07:00";
     table.Rows.Add(dr);
     dr = table.NewRow();
     dr[0] = "07:00-08:00";
     table.Rows.Add(dr);
     // Create a bar series
     BarSeries series = new BarSeries();
     series.SeriesName = "Series 0";
     series.Values.Add(2.0);
     series.Values.Add(4.0);
     series.Values.Add(3.0);
     series.Values.Add(5.0);
     // Show Axis Labels from the DataSource
     series.CategoryNames.DataField = "Category";
     series.CategoryNames.DataSource = table;
    
    VB
    Copy Code
    Dim table As DataTable = New DataTable()
    Dim dr As DataRow = table.NewRow()
    table.Columns.Add("Category")
    dr(0) = "03:00-04:00"
    table.Rows.Add(dr)
    dr = table.NewRow()
    dr(0) = "04:00-05:00"
    table.Rows.Add(dr)
    dr = table.NewRow()
    dr(0) = "06:00-07:00"
    table.Rows.Add(dr)
    dr = table.NewRow()
    dr(0) = "07:00-08:00"
    table.Rows.Add(dr) 
    ' Create a bar series
    Dim series As BarSeries = New BarSeries()
    series.SeriesName = "Series 0"
    series.Values.Add(2.0)
    series.Values.Add(4.0)
    series.Values.Add(3.0)
    series.Values.Add(5.0)
    ' Show Axis Labels from the DataSource
    series.CategoryNames.DataField = "Category"
    series.CategoryNames.DataSource = table
    

     Using the Chart Designer

    1. Select the PlotArea from the Format menu.
    2. Select the XAxis and YAxis Collections
    3. Set the Title and other properties, as needed.
    4. Select Apply and OK to close the Chart Designer.