Spontaneous Publicity
blogs are the new phone book

Google Charts for Asp.Net now on Codeplex

February 10, 2008 12:59 by Luke

image I have received very positive feedback on my Asp.Net control for Google charts so I decided to place it up on Codeplex to allow people to participate and add code to the project.

I am currently working on a project roadmap so please let me know if you are interested in participating. One feature I have already begun work on is giving the control support for data binding.

Here is some example data binding code I have got working:

protected void Page_Load(object sender, EventArgs e)
{
    chart.DataSource = GetDataSource();
    chart.DataBind();
}

private DataTable GetDataSource()
{
    DataTable table = new DataTable();
    
    table.Columns.Add("Type", typeof(string));
    table.Columns.Add("Jan", typeof(float));
    table.Columns.Add("Feb", typeof(float));
    table.Columns.Add("Mar", typeof(float));

    table.Rows.Add("Men", 68, 78, 88);
    table.Rows.Add("Women", 68, 58, 78);
    table.Rows.Add("Both", 88, 48, 98);
    return table;
}

I am just binding to a simple DataTable which has one column containing the labels for the chart and multiple other columns which contain the data for the chart. The code above produces the following chart:

image

I look forward to seeing this project improve.

kick it on DotNetKicks.com
Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (2) | Comment RSSRSS comment feed

Comments

October 10. 2008 13:21

tony

I just saw that you are 'working' on the databinding... Can you send me the code that works? I would LOVE it! I can help you with this if you want. Where is the latest code that has the property for the datasource off of the chart class?

tony

October 10. 2008 13:26

tony

The code you have here in the example doesnt work...

C:\work\gChart\Default.aspx.cs(17,15): error CS0117: 'Web.Google.Chart' does not contain a definition for 'DataSource'

_______C#_________

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Web.Google;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        chart.DataSource = GetDataSource();
        chart.DataBind();
    }

    private DataTable GetDataSource()
    {
        DataTable table = new DataTable();

        table.Columns.Add("Type", typeof(string));
        table.Columns.Add("Jan", typeof(float));
        table.Columns.Add("Feb", typeof(float));
        table.Columns.Add("Mar", typeof(float));

        table.Rows.Add("Men", 68, 78, 88);
        table.Rows.Add("Women", 68, 58, 78);
        table.Rows.Add("Both", 88, 48, 98);
        return table;
    }
}

_______aspx_________

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Web.Google.Chart" Namespace="Web.Google" TagPrefix="web" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/.../xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <web:Chart  ID="chart"
                    runat="server"
                    Width="300px"
                    Height="150px"
                    Title="Transportation"
                    Type="Line"
                    EnableLegend="true">    
        </web:Chart>
    </div>
    </form>
</body>
</html>





tony