【问题标题】:How to add a legend for multiple series in ms chart c#如何在 ms 图表 c# 中为多个系列添加图例
【发布时间】:2016-10-18 22:28:10
【问题描述】:

我一直在研究 ASP.NET MVC razor 项目、C#、Visual Studio 2012。我有一个包含两个系列的图表。

我的代码是:

var chartCentersByYear = new Chart
            {
                Width = 1000,
                Height = 450,
                RenderType = RenderType.ImageTag,
                AntiAliasing = AntiAliasingStyles.Graphics,
                TextAntiAliasingQuality = TextAntiAliasingQuality.High


            };

            chartCentersByYear.Series.Add("Count");
            chartCentersByYear.Series.Add("Cases");
            chartCentersByYear.Series[0].ChartType = SeriesChartType.Column; 
            chartCentersByYear.Series[1].ChartType = SeriesChartType.Line;
var totalCentersByYearResult = new Repository().GetTotalCentersByYear();

            foreach (IGD_spInternationalReportCenterWithTots_Result item in totalCentersByYearResult)
            {
                chartCentersByYear.Series[0].Points.AddXY(item.YearEcmo, item.Count);
                chartCentersByYear.Series[1].Points.AddY(item.Cases);
            }

...等等。我必须在图表中插入一个图例以在同一个图例中显示两个系列。我需要在图例符号旁边显示值,计数 83,86,93 ... 等以及每年的案例 1644,1775,1933 等。我怎样才能做到这一点?提前感谢您的帮助。

【问题讨论】:

  • 你用的是什么图表库?
  • 我正在使用 System.Web.DataVisualization.dll、命名空间 System.Web.UI.DataVisualization.Charting 和 System.Drawing.dll

标签: c# asp.net charts legend


【解决方案1】:
Legend secondLegend = new Legend("MyLegend");

this.Chart1.Legends.Add("MyLegend");

// Associate Series 2 with the second legend 
chartCentersByYear.Series[0].Legend = "MyLegend";
chartCentersByYear.Series[1].Legend = "MyLegend";
chartCentersByYear.Series[2].Legend = "MyLegend";
chartCentersByYear.Series[3].Legend = "MyLegend";

【讨论】:

    猜你喜欢
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多