Single 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_SS_Code()
{
    // Create a chart
    Column3DChart oChart = new Column3DChart();
 
    // Set properties
    oChart.Background.BgColor = "ffffff";
    oChart.Canvas3D.CanvasBgColor = "eeeeee";
    oChart.ChartTitles.Caption = "Top seller";
    oChart.ChartTitles.SubCaption = "November";
 
    // Set a template
    oChart.Template = new Libero.FusionCharts.Template.OfficeTemplate();
 
    // Set data
    foreach (Sales s in GetSales())
    {
        oChart.Set.Add(new SSSetElement { Name = s.SalesmanName, Value = s.TotalSold, ShowName = true });
    }
 
    // Add trend lines
    oChart.TrendLines.Add(new TrendLineElement { StartValue = 530, EndValue = 533, Color = "33dd33", DisplayValue = "Very good" });
    oChart.TrendLines.Add(new TrendLineElement { StartValue = 200, EndValue = 203, Color = "dd3333", DisplayValue = "Very bad" });
 
    //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">
         Charts
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Single Series Chart, adding data manually.</h2>
    <br />

    <%=Html.FChart("Chart01", ViewData["MyChart"], 600, 400)%>

</asp:Content>

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

Comments

No comments yet.