Background image with chart control / helper in Razor

风流意气都作罢 提交于 2019-12-13 07:25:23

问题


when using the chart helper in MVC5, how can I set a background image to the chart? There is a Chart.BackImage Property in the "original" Chart control. Is the helper only a small subset or is there a way to assign it with themes?


回答1:


Use a template, as follows:

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

You can also place the BackImage attribute in the Chart tag:

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


来源:https://stackoverflow.com/questions/35087744/background-image-with-chart-control-helper-in-razor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!