有没有办法使用图表助手在图表上显示图例?
默认情况下它不会显示,我也无法指定属性来显示。如果我在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" });
出现错误: Series 'Series1' 使用不存在的图例名称 'Rainfall'。将 Legend 属性值设置为 Default。
如果我将 legend: "Rainfall"
更改为 legend: "Default"
,会得到相同的错误。
如何使此图例名称存在?例如,在直接使用 System.Web.UI.DataVisualization.Charting
的情况下,它将看起来像这样:
chart.Legends.Add("Legend1");
// show legend based on check box value
chart.Legends["Legend1"].Enabled = true;
但是如何使用helper实现相同的功能呢?