ASP.NET MVC图表助手.如何为图表上的每个条/列设置不同的颜色?

Jok*_*ker 9 charts asp.net-mvc-3

我正在使用ASP.NET MVC 3.0 Chart Helper.

Rainfall出于某种原因,颜色方案(例如)仅适用于饼图和圆环图,而不适用于任何其他类型(条形图,柱形等).

所有其他图表上的条/列具有相同的颜色.如何解决?

这是我的图表:

chart = new System.Web.Helpers.Chart(width: 100, height: 200)
                .AddSeries(
                    chartType: Bar,
                    legend: Rainfall
                    xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
                    yValues: new[] { "20", "20", "40", "10", "10" });
            }
Run Code Online (Sandbox Code Playgroud)

此外,我试图使用所有方案System.Web.Helpers public static class ChartTheme,这些都没有帮助

Mar*_*way 6

我发现了一些有用的东西......它不是很好但它有效

使用旧图表

使用System.Web.UI.DataVisualization.Charting;


 public ActionResult GetRainfallChart()
    {
        Chart chart = new Chart();
        chart.BackColor = Color.Transparent;
        chart.Width = Unit.Pixel(1400);
        chart.Height = Unit.Pixel(750);

        Series series1 = new Series("Series1");
        series1.ChartArea = "ca1";
        series1.ChartType = SeriesChartType.Bar;
        series1.Font = new System.Drawing.Font("Verdana", 11f, FontStyle.Regular);
        series1.Points.Add(new DataPoint
        {
            AxisLabel = "A",
            YValues = new double[] { 100 },
            Color = Color.Green,
        });
        series1.Points.Add(new DataPoint
        {
            AxisLabel = "B",
            YValues = new double[] { 324 },
            Color = Color.Red,
        });
        series1.Points.Add(new DataPoint
        {
            AxisLabel = "C",
            YValues = new double[] { 235 },
            Color = Color.Yellow,
        });

        chart.Series.Add(series1);

        ChartArea ca1 = new ChartArea("ca1");
        ca1.BackColor = Color.Transparent;
        chart.ChartAreas.Add(ca1);

        var ms = new MemoryStream();

        chart.SaveImage(ms, ChartImageFormat.Png);
        ms.Seek(0, SeekOrigin.Begin);

        return new FileStreamResult(ms, "image/png");



    }
Run Code Online (Sandbox Code Playgroud)

是的,他是对的.System.Web.Helpers中的另一个信息Chart Helper在内部使用'using DV = System.Web.UI.DataVisualization.Charting;' 仅限ASP.Net图表控件,但包含有限的访问权限.

如果您需要更多功能,可以使用ASP.Net图表