Multi Series Chart, adding data manually.

If you haven`t already, see Setting up for a MVC project.

In your controller or model you will define: (just as an example we will define everything on the controller) 

  • The type of chart you want (see supported charts).
  • All appearence properties, as backgroung color, titles, and so on.
  • And the main part, the data.
public ActionResult Sample_MS_Code()
{
    MSColumn3DChart oChart = new MSColumn3DChart();
 
    // Set properties
    oChart.Background.BgColor = "ffffff";
    oChart.Background.BgAlpha = 50;
    oChart.ChartTitles.Caption = "Categories by country";
    oChart.ChartTitles.SubCaption = "Annual report (US$)";
 
    // Set a template
    oChart.Template = new Libero.FusionCharts.Template.OceanTemplate();
 
    // Set data
    // Add Categories Data.
    oChart.CategorySet.FontColor = "0000FF";
    oChart.CategorySet.CategoryElementSet.Add(new MSCategoryElement("Brazil"));
    oChart.CategorySet.CategoryElementSet.Add(new MSCategoryElement("India"));
    oChart.CategorySet.CategoryElementSet.Add(new MSCategoryElement("China"));
 
    // Add Series data in the correct order.
    MSDataSet msDs;
    msDs = new MSDataSet("Eletronics""ff0000");
    msDs.SetElementSet.Add(new MSSetElement(15000));
    msDs.SetElementSet.Add(new MSSetElement(30000));
    msDs.SetElementSet.Add(new MSSetElement(45000));
    oChart.DataSetList.Add(msDs);
 
    msDs = new MSDataSet("Computers""00ff00");
    msDs.SetElementSet.Add(new MSSetElement(80000));
    msDs.SetElementSet.Add(new MSSetElement(50000));
    msDs.SetElementSet.Add(new MSSetElement(20000));
    oChart.DataSetList.Add(msDs);
 
    msDs = new MSDataSet("Mobiles""0000ff");
    msDs.SetElementSet.Add(new MSSetElement(15000));
    msDs.SetElementSet.Add(new MSSetElement(30000));
    msDs.SetElementSet.Add(new MSSetElement(70000));
    oChart.DataSetList.Add(msDs);
 
    //Load it into ViewData.
    ViewData["MyChart"] = oChart;
 
    return View();
}

 

And our view will be:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="MvcApplication1" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Sample_MS_Code
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
    <h2>Multi Series Chart, adding data manually.</h2>
    <br />
    <%=Html.FChart("Chart01", ViewData["MyChart"], 600, 400)%>
 
</asp:Content>

Last edited Nov 27, 2010 at 5:52 PM by robertobarbedo, version 5

Comments

No comments yet.