Razor 中带有图表控件/助手的背景图像

Background image with chart control / helper in Razor

在MVC5中使用图表助手时,如何给图表设置背景图片? "original" Chart控件中有一个Chart.BackImage 属性。 助手只是一小部分,还是有办法为其分配主题?

使用模板,如下:

string template = @"<Chart>
  <ChartAreas>
     <ChartArea Name=""Default"" BackImage=""/Content/Images/chart.jpg"">
     </ChartArea>
  </ChartAreas>
</Chart>";

var myChart = new Chart(width: 600, height: 400, theme: template)
    .AddTitle("Title")
    .AddSeries(
        name: "Values",
        xValue: new[] { "A", "B", "C", "D", "E" },
        yValues: new[] { "1", "2", "3", "4", "5" })
    .Write();

您还可以将 BackImage 属性放在 Chart 标签中:

<Chart BackImage=\"/Content/Images/chart.jpg\">...</Chart>