Search code examples
asp.net-mvcmschart

.Net MVC Radar Chart Polygon?


I'm trying to create a radar chart with the drawing style as polygon instead of circle in the MVC chart helper but i cannot find the AreaDrawingStyle anywhere in it.

I know in the regular ASP chart control i can do:

chart1.Series["Default"]["AreaDrawingStyle"] = "Polygon";

But in my MVC code, i have:

Chart myChart = new Chart(width: 600, height: 400)
            .AddTitle("Chart Title")
            .AddSeries(
                name: "Employee",
                chartType: "Radar",
                xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
                yValues: new[] { "20", "60", "41", "55", "33" });

Does anyone know where to find it? I searched lots of places but i am having a hard time finding specific details about this particular type of chart.


Solution

  • I just had to make my MVC chart use polygon as well. This link helped me a lot by allowing me to style the chart using the underlying System.Web.UI.DataVisualization.Charting classes: http://truncatedcodr.wordpress.com/2012/09/18/system-web-helpers-chart-custom-themes/

    In short, try this nasty stuff...

    System.Web.UI.DataVisualization.Charting.ChartArea ca = new System.Web.UI.DataVisualization.Charting.ChartArea("Default");
    
    var chart = new System.Web.UI.DataVisualization.Charting.Chart();
    chart.Series.Add("MySeries");
    chart.Series["MySeries"]["AreaDrawingStyle"] = "Polygon";
    
    var cs = chart.Serializer;
    cs.IsTemplateMode = true;
    cs.Format = System.Web.UI.DataVisualization.Charting.SerializationFormat.Xml;
    var sb = new System.Text.StringBuilder();
    using ( System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb))
    {
        cs.Save(xw);
    }
    string theme = sb.ToString().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
    
    System.Web.Helpers.Chart myChart = new System.Web.Helpers.Chart(width: 1024, height: 768, theme:theme);
    

    And now you have a whole new name space to look into for formatting your charts!