How to change the default colors of a pie chart when using the chart helper in ASP.NET MVC

Can I indicate what color looks in each section of the cake? Also, is it possible to display the legend from the side?

For example: in the table below, can I indicate that "Pass" is displayed in green, Fail as red and is not known as gray?

public ActionResult GetRainfallChart() { var key = new Chart(width: 600, height: 400).AddSeries( chartType: "pie", legend: "Test pass", xValue: new[] { "Pass", "Fail", "Unknown" }, yValues: new[] { "50", "30", "20" }) .Write(); return null; } 

If this is not possible using the β€œchart” control, which is part of the System.Web.Helpers assembly, can someone tell me how to do this using asp.net controls for web forms in an MVC project.

+4
source share
4 answers

to show the legend ...

 chart.Legends.Add(new Legend("Default") { Docking = Docking.Right }); 
+1
source

You can set the color in a series. There is a Color property.

For instance:

 // Set color for the whole series Chart.Series[0].Color = Color.Green; // Set color of a single data point Chart.Series[0].Points[5].Color = Color.Red; 

For more on colors, see this blog post: Customizing Microsoft Series Chart Colors

+2
source

Unfortunately, Chart does not have the "Series" property that is displayed. FYI, I'm talking about the "Chart" class present in the System.web.Helpers assembly, which can be used in the asp.net mvc application and not the same as the "diagram" that is included in the System.data.visualization assembly that comes with asp.net web form application

+2
source

You can specify the range of colors you want in the .SeriesColors Chart Property,

 .SeriesColors(new string[] { "#952F91", "#00A9AA", "#EA7EB8" /*...range of colors */ }) 
0
source

Source: https://habr.com/ru/post/1337432/


All Articles