ASP.NET MVC 3.0 Chart Helper 显示图例
有没有办法使用图表助手在图表上显示图例?
默认情况下它不显示它,没有我可以说要显示的属性,如果我在 xml 中指定图例:
<Legends>
<Legend _Template_=""All"" BackColor=""Black"" Docking=""Bottom"" Font=""Trebuchet MS, 8.25pt, style=Bold"" LegendStyle=""Row"" >
</Legend>
</Legends>
它也不起作用。
图表助手中有一个方法 public Chart AddLegend(string title = null, string name = null)
;但是当我调用它时,我看不到图表上的图例,图表也没有显示。
Chart chart = new System.Web.Helpers.Chart(width: 120, height: 300, theme: chartStyle: ChartTheme.Green.ToString())
.AddLegend("title", "name") // not existed legends, that's why error.
.AddSeries(
chartType: "Column"
legend: "Rainfall"
xValue: new[] { "jan", "feb", "mar", "apr", "may" },
yValues: new[] { "20", "20", "40", "10", "10" });
出现错误:系列“Series1”使用不存在的图例名称“Rainfall”。将图例属性值设置为默认
如果我将图例:“Rainfall”
更改为图例:“Default”
,则会出现相同的错误。
我怎样才能让这个传奇的名字存在呢?例如,如果直接使用 System.Web.UI.DataVisualization.Charting
,它将看起来像这样:
chart.Legends.Add("Legend1");
// show legend based on check box value
chart.Legends["Legend1"].Enabled = true;
但是如何使用助手实现同样的事情呢?
Is there any way to display legend on chart using chart helper?
It is not displaying it by default, there is no property i can say to display and if i specify legend in xml :
<Legends>
<Legend _Template_=""All"" BackColor=""Black"" Docking=""Bottom"" Font=""Trebuchet MS, 8.25pt, style=Bold"" LegendStyle=""Row"" >
</Legend>
</Legends>
It is also not working.
There is method in chart helper public Chart AddLegend(string title = null, string name = null)
; but when i am calling it i can't see not the legend on my chart, chart not displaying as well.
Chart chart = new System.Web.Helpers.Chart(width: 120, height: 300, theme: chartStyle: ChartTheme.Green.ToString())
.AddLegend("title", "name") // not existed legends, that's why error.
.AddSeries(
chartType: "Column"
legend: "Rainfall"
xValue: new[] { "jan", "feb", "mar", "apr", "may" },
yValues: new[] { "20", "20", "40", "10", "10" });
.Getting error: Series 'Series1' uses non-existing legend name 'Rainfall'. Set Legend property value to Default
If i change legend: "Rainfall"
to legend: "Default"
getting same error.
How could i make this legend name existed? For example in case of using System.Web.UI.DataVisualization.Charting
directly it will be looking like that:
chart.Legends.Add("Legend1");
// show legend based on check box value
chart.Legends["Legend1"].Enabled = true;
But how to achieve the same thing with helper?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为每个系列命名,然后调用不带参数的 AddLegend() 来添加图例。
You need to give each Series a name, then call the AddLegend() with no parameters to add the Legend.