Open Flash Chart .NET
Open Flash Chart .NET (OFC.NET) is based on the Open Flash Chart project located athttp://teethgrinder.co.uk/open-flash-chart (or SourceForge). Source code for OFC.NET is located on a Subversion server provided by K2 Colocation athttp://svn.k2colocation.com/svn/OpenFlashChart. OFC.NET is licensed under an new BSD license which allows users to use the source in any way they see fit including creating a derivative closed source version.
Installation: To install OFC.NET for use in your web project you will need to follow the steps below.
- You will need to create a aspnet_client directory if one does not already exist in the root directory of your ASP.NET project.
- A subdirectory of aspnet_client must be created with the nameOpenFlashChart.
- In the OpenFlashChart directory you will need the file open-flash-chart.swf and the subdirectory js.
- The js directory must contain the file swfobject.js.
- Your .NET web project must reverence either the compiled OFC.NET library (OpenFlashChart.dll) or the code which can be retrieved via subversion using a svn client (I recommend TortoiseSVN for Windows users).
Usage: To use OFC.NET on a page in your .NET project you will need to register the library using the following command: <%@Register TagPrefix="ofc" Namespace="OpenFlashChart" Assembly="OpenFlashChart" %>. Once the library has been registered you can begin creating graphs using the chart tag (Ex.<ofc:Chart Width="400" Height="400" Url="data.aspx" runat="Server" />). The url parameter of the chart tag specifies the source of the chart data, this can be a static file or can be generated dynamically using the OFC.NET library.
Example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@Register TagPrefix="ofc" Namespace="OpenFlashChart" Assembly="OpenFlashChart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/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>
<ofc:Chart Width="400" Height="400" Url="data.aspx" runat="Server" />
</div>
</form>
</body>
</html>
Dynamic Chart Data: Chart data is created by instantiating the Graph class. In this class properties can be set such as background colors, labels, tooltips etc. These properties define the look and feel of the chart. Next the Charts.ChartData base class is used to define the type of chart as well as the data. Once the data has been created the Charts.ChartData can be added to the Graph object using theGraph.Data.Add(Charts.ChartData) method. When rendered charts can display more than one type of graph with in the same chart with the exception of the pie chart.
Example: AreaHollow
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 OpenFlashChart;
public partial class data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Graph graph = new Graph();
graph.LegendX = new LegendX("Chart Test", 12, "#FF0000");
graph.StepsY = 5;
graph.MaxY = 50;
OpenFlashChart.Charts.ChartData temp;
temp = new OpenFlashChart.Charts.AreaHollow(2, 3, "#0000CC", 75, "Profit", 12, "#AAAAFF");
temp.Data.Add(20);
temp.Data.Add(30);
temp.Data.Add(40);
temp.Data.Add(10);
graph.Data.Add(temp);
Response.Clear();
Response.Write(graph.ToString());
Response.End();
}
}
Example: Line
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 OpenFlashChart;
public partial class data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Graph graph = new Graph();
graph.LegendX = new LegendX("Chart Test", 12, "#FF0000");
graph.StepsY = 5;
graph.MaxY = 50;
OpenFlashChart.Charts.ChartData temp;
// Line(Line Size, color (Hex), Label, Label Font Size, Size of Circles (Points))
temp = new OpenFlashChart.Charts.Line(2, "#FF0000", "Sales", 12, 3);
temp.Data.Add(20);
temp.Data.Add(30);
temp.Data.Add(40);
temp.Data.Add(10);
graph.Data.Add(temp);
Response.Clear();
Response.Write(graph.ToString());
Response.End();
}
}
Example: Bar
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 OpenFlashChart;
public partial class data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Graph graph = new Graph();
graph.LegendX = new LegendX("Chart Test", 12, "#FF0000");
graph.StepsY = 5;
graph.MaxY = 50;
OpenFlashChart.Charts.ChartData temp;
// Bar(alpha (transparency), color (Hex), Label, Line Size)
temp = new OpenFlashChart.Charts.Bar(75, "#FF0000", "Sales", 2);
temp.Data.Add(20);
temp.Data.Add(30);
temp.Data.Add(40);
temp.Data.Add(10);
graph.Data.Add(temp);
Response.Clear();
Response.Write(graph.ToString());
Response.End();
}
}
Example: Pie
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 OpenFlashChart;
public partial class data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Graph graph = new Graph();
graph.LegendX = new LegendX("Chart Test", 12, "#FF0000");
graph.StepsY = 5;
graph.MaxY = 50;
// Pie(alpha, line color, label);
graph.Pie = new OpenFlashChart.Charts.Pie(75, "#000000", "Sales By Region");
graph.Pie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(33, "South", "#FF0000"));
graph.Pie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(20, "North", "#00FF00"));
graph.Pie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(40, "West", "#0000FF"));
graph.Pie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(7, "East", "#FFFFFF"));
Response.Clear();
Response.Write(graph.ToString());
Response.End();
}
}
浙公网安备 33010602011771号