开发者

How can I draw a Radar Chart using Microsoft Chart Control for .NET Framework 3.5

How can I draw a Radar Chart using Microsoft Chart Control for .NET Framework 3.5. I can draw "column" chart using the following code fro开发者_StackOverflowm MSDN. I could not find any example for Radar Chart.

    Series ChampionshipsSeries = chtNBAChampionships2.Series["Championships"];
    //Add data points 
    ChampionshipsSeries.Points.AddXY("Celtics", 17);
    ChampionshipsSeries.Points.AddXY("Lakers", 15);
    ChampionshipsSeries.Points.AddXY("Bulls", 6);
    ChampionshipsSeries.Points.AddXY("Spurs", 4);
    ChampionshipsSeries.Points.AddXY("76ers", 3);
    ChampionshipsSeries.Points.AddXY("Pistons", 3);
    ChampionshipsSeries.Points.AddXY("Warriors", 3);

Looking for your kind help.


Finally I managed myself after doing experimenting with the examples from the following source,

Samples for Chart Control - .NET Framework 4

Though the examples are for .NET Framework 4, I tried it in .NET Framework 3.5 for Radar Chart and it worked.

If you are interested you may have a look at this page, http://nazmulweb.com/site5/demo/chart/

Later on , I have found the examples for .NET Freamework 3.5 from http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591

As a ready reference, you can follow this one,

        /*
    --------------------------
    Criteria    Volvo   Toyota
    --------    -----   ------
    Speed       37      23
    Fuel        32      19
    Comfort     38      31
    Safety      39      33
    --------------------------
    */

    DataTable dt = new DataTable();
    dt.Columns.Add("Criteria");
    dt.Columns.Add("Volvo");
    dt.Columns.Add("Toyota");
    DataRow dr1 = dt.NewRow();
    dr1.ItemArray = new object[] { "Speed", 37, 23 };
    dt.Rows.Add(dr1);
    DataRow dr2 = dt.NewRow();
    dr2.ItemArray = new object[] { "Fuel", 32, 19 };
    dt.Rows.Add(dr2);
    DataRow dr3 = dt.NewRow();
    dr3.ItemArray = new object[] { "Comfort", 38, 31 };
    dt.Rows.Add(dr3);
    DataRow dr4 = dt.NewRow();
    dr4.ItemArray = new object[] { "Price", 39, 33 };
    dt.Rows.Add(dr4);

    Chart aRadarChart = new Chart();
    aRadarChart.Width = Unit.Pixel(500);
    aRadarChart.DataSource = dt;
    // Add title 
    aRadarChart.Titles.Add("TOYOTA VS VOLVO");
    // Add a legend 
    Legend lgnd = new Legend();
    lgnd.Enabled = true;
    aRadarChart.Legends.Add(lgnd);

    //Important: add ChartArea, otherwise no graph will be shown
    ChartArea ca = new ChartArea("myChartArea");
    aRadarChart.ChartAreas.Add(ca);

    string car = String.Empty;
    for (int i = 1; i < dt.Columns.Count; i++)
    {
        car = dt.Columns[i].ColumnName;

        aRadarChart.Series.Add(car);//Name of the series :Volvo and Toyota
        aRadarChart.Series[car].YValueMembers = car;//Either Volvo or Toyota
        aRadarChart.Series[car].XValueMember = dt.Columns[0].ColumnName;//Criteria
        //Define here: what kind of Chart you want
        aRadarChart.Series[car].ChartType = SeriesChartType.Radar;
    }

    //binding data
    aRadarChart.DataBind();
    //Add Chart to a PlaceHolder Control
plhForChart.Controls.Add(aRadarChart);
    //Page.Controls.Add(aRadarChart);

    //for saving image
    aRadarChart.SaveImage(Server.MapPath("App_Data/Sample.jpg"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜