c#图表,如何添加标签

时间:2018-03-23 02:34:29

标签: c# asp.net-mvc charts

我是System.Web.Helpers.Chart的新手。 我尝试使用图表生成报告和显示。

以下是我用于生成报告之一的代码

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");

    }

我得到的结果就是这个

enter image description here

我是否知道如何在图像中突出显示每个条形列的值数?

1 个答案:

答案 0 :(得分:0)

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

还尝试使用以下代码为图例添加更具体的控件:

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