Ng Zheng
Ng Zheng

Reputation: 59

c# Chart, how to add label

I am new to System.Web.Helpers.Chart . I try to generate report and display using chart.

Below is my code that i use to generate one of my report

public ActionResult columnChartForECNWithoutECO()
    {
        ArrayList xValueDraft = new ArrayList();
        ArrayList xValueWithoutECO = new ArrayList();
        ArrayList yValue = new ArrayList();
        SAMMeerkatECCSDataAccess dataAccess = new SAMMeerkatECCSDataAccess();
        System.Data.DataTable results = dataAccess.reportGetECNWithoutECOByUser();

        foreach (DataRow row in results.Rows)
        {

            xValueDraft.Add(row["Draft"].ToString());
            xValueWithoutECO.Add(row["WithoutECO"].ToString());
            yValue.Add(row["userName"].ToString());
        }

        var key = new System.Web.Helpers.Chart(width: 600, height: 400, theme: ChartTheme.Vanilla)
           .AddTitle("Total ECN Without ECO By User").AddLegend("Details")
           .AddSeries
           (

               chartType: "Column",
               xValue: yValue,
               yValues: xValueDraft, 
               axisLabel: "Bar 1",
               name: "ECO Draft"
           )
           .AddSeries(
           chartType: "Column",
            axisLabel: "Bar 2",
           xValue: yValue,
           yValues: xValueWithoutECO,
           name: "Without ECO"
           );



        return File(key.ToWebImage().GetBytes(), "image/jpeg");

    }

and the result i get is this

enter image description here

May I know how can I show the number of value on every bar column as highlighted in the image ?

Upvotes: 1

Views: 6341

Answers (1)

David
David

Reputation: 16277

var chart = new Chart(width: 600, height: 250)
        .AddSeries(
            ...)
        .AddSeries(
            ...)
        .AddLegend();  //Add this

Also try to use below code to add more specific control to the legend:

chart.Series["Data"].Label = "#PERCENT{P0}";
chart.Series["Data"].Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
chart.Series["Data"].ChartType = SeriesChartType.Pie;
chart.Series["Data"]["PieLabelStyle"] = "Outside";
chart.Series["Data"].Legend = "Stores";
chart.Legends["Stores"].Docking = Docking.Bottom;

enter image description here

Upvotes: 1

Related Questions