This project is read-only.

Single Series Chart, adding data from a datasource - MVC.

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

Supose your data is comming from a database in the following way:

Just as a example, we are going to define our chart in the Controller, You may find better to desing your code in other way like retrieving a chart from the your model.

public ActionResult Sample_SS_Datasource()
    // Create a chart
    Pie2DChart oChart = new Pie2DChart();
    // Set properties
    oChart.Background.BgColor = "ffffff";
    oChart.Background.BgAlpha = 50;
    oChart.ChartTitles.Caption = "Top seller (%)";
    oChart.ChartTitles.SubCaption = "November";
    // Set a template
    oChart.Template = new Libero.FusionCharts.Template.OfficeTemplate();
    // Set data
    DataTable dtSample = GetSalesDataTable();
    oChart.DataSource = dtSample;
    oChart.DataTextField = "SallesmanName";
    oChart.DataValueField = "PercentTotalSell";
    //Load it into ViewData.
    ViewData["MyChart"] = oChart;
    return View();


And our is simple like this:

<%@ 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">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Single Series Chart, adding data from a datasource.</h2>
    <br />

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


Last edited Nov 27, 2010 at 9:09 AM by robertobarbedo, version 5


No comments yet.