How do I change the parameters of a chart (for example, the color of the cutoff pie) in a chart created using the Razor chart assistant?

I follow the Razor ASP.NET Page Guide for creating diagrams in ASP.NET MVC 3 view.

I can create / display a pie chart. But I don’t see how to change the colors of the slides of the cake - or to explode a slice.

I tried to reference the "Series" collection of the Chart object, but it is not visible.

Here is a piece of code that I have.

<td> @{ Chart chart = new Chart(width: 100, height: 100) .AddSeries(chartType: "Pie", name: "Dafault", xValue: new[] { "Yes", "No" }, yValues: new[] { 70.2m, 29.8m }); chart.Write(); } </td> 

Can someone tell me how I will do this?

+4
source share
2 answers

Dommer

I'm only one step ahead of you, but you can create your own colors using the "themePath" property in the Chart constructor. This is not well documented, but themePath is the path to an XML document that describes the diagram in detail. You can get XML samples by doing intellisense on string constants in Theme (which is an optional third parameter in the chart constructor).

You can find a link to themePath values ​​and a sample XML at the following link: http://www.mikepope.com/blog/documents/WebHelpersAPI.html#Chart

Now custom colors. The XML in the theme files shows the Palette attribute in the Chart element. Set it to None and add the PaletteCustomColors attribute with a set of RGB values, for example:

PaletteCustomColors = '0,0,255; 0.255.0; 255.0.0; 0,255,255; 255.0.255; 255,255,0

Refer to yourPart tag in the constructor as follows:

 string pathName = "~/Content/Test3DTheme.xml"; var chart = new Chart(width: 600, height: 400, themePath: pathName) [add methods here] 

That should do it. Aside, it seems that the abstract protocol uses a lot of attributes, which are properties in System.Web.UI.DataVisualization.Chart. You can experiment (as I am doing now) by adjusting and adding / removing attributes to see what will change the look of your chart and what will break it. The parser is very perceptive about the attributes that it takes.

Hope this helps.

Jim Stanley

Blackboard Connect Inc.

+5
source

Using Charting is available in the System.Web.Helpers namespace. You will need the full charting component available in the System.Web.UI.DataVisualization namespace. Here is a link to get started Diagram with MVC Here is a link on how to use full blast features with interactivity. Interactivity chart

+1
source

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


All Articles