dpv
dpv

Reputation: 157

Set label to X-values on a chart ASP.NET

I have a chart in ASP.NET (.NET 3.5) that contains 3 series. The date is filled dynamic in code. How can I set a label to each X-entry from code? (Label1, Label2, Label3, etc) Chart example

Upvotes: 0

Views: 1605

Answers (1)

Hans Derks
Hans Derks

Reputation: 1027

Maybe you mean this

in aspx

<asp:Chart ID="Chart1" runat="server" Height="400px" Width="500px">
    <Series>
        <asp:Series Name="Series1" ChartType="Column" ChartArea="ChartArea1" />
        <asp:Series Name="Series2" ChartType="Column" ChartArea="ChartArea1" />
        <asp:Series Name="Series3" ChartType="Column" ChartArea="ChartArea1" />
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1" />
    </ChartAreas>
</asp:Chart>

Binding data

  protected void Page_Load(object sender, EventArgs e)
        {
            // Initialize arrays for series 1
            double[] yval1 = { 2, 6, 5 };
            string[] xval1 = { "Peter", "Andrew", "Julie" };

            // Initialize arrays for series 2
            double[] yval2 = { 4, 5, 3 };
            string[] xval2 = { "Peter", "Andrew", "Julie" };

            // Initialize arrays for series 3
            double[] yval3 = { 6, 5,7 };
            string[] xval3 = { "Peter", "Andrew", "Julie" };

            // Bind the arrays to each data series
            Chart1.Series["Series1"].Points.DataBindXY(xval1, yval1);
            Chart1.Series["Series2"].Points.DataBindXY(xval2, yval2);
            Chart1.Series["Series3"].Points.DataBindXY(xval3, yval3);

            // Align series using their X axis labels
            Chart1.AlignDataPointsByAxisLabel();

        }

Upvotes: 1

Related Questions