由于项目需要画统计图,经讨论,我们选用了dotnetcharting这个控件。dotnetcharting是一款非常棒的生成统计图表的控件,开发人员只需要参考范例,掌握思路,就能够自己自由的编写代码,实现各种各样的统计效果图。正版dotnetcharting是需要购买的,价格目前官方网站上显示是$395,相当的昂贵哦。不过中国人很聪明,现在到处可以下载破解版了。dotnetcharting目前已经支持.net Framework 2.0, 3.0, and 3.5了,有c#和vb.net版本。相当的不错!
下面是几个截图,看看效果如何?
(图1) 2D柱状图
(图2) 3D饼状图
(图3) 股票走势图
dotnetcharting还能作出各种各样的图表出来,在此就不一一罗列了。现附上(图1)的代码:
C#
<%@ Page Language="C#" Description="dotnetCHARTING Component"%>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
SeriesCollection getRandomData()
{
SeriesCollection SC = new SeriesCollection();
Random myR = new Random();
for(int a = 0; a < 4; a++)
{
Series s = new Series();
s.Name = "Series " + a;
for(int b = 0; b < 5; b++)
{
Element e = new Element();
e.Name = "E " + b;
e.YValue = myR.Next(50);
s.Elements.Add(e);
}
SC.Add(s);
}
// Set Different Colors for our Series
SC[0].DefaultElement.Color = Color.FromArgb(49,255,49);
SC[1].DefaultElement.Color = Color.FromArgb(255,255,0);
SC[2].DefaultElement.Color = Color.FromArgb(255,99,49);
SC[3].DefaultElement.Color = Color.FromArgb(0,156,255);
return SC;
}
void Page_Load(Object sender,EventArgs e)
{
// Set the title.
Chart.Title="My Chart";
// Set the x axis label
Chart.ChartArea.XAxis.Label.Text="X Axis Label";
// Set the y axis label
Chart.ChartArea.YAxis.Label.Text="Y Axis Label";
// Set the directory where the images will be stored.
Chart.TempDirectory="temp";
// Set the bar shading effect
Chart.ShadingEffect = true;
// Set he chart size.
Chart.Width = 600;
Chart.Height = 350;
// Add the random data.
Chart.SeriesCollection.Add(getRandomData());
}
</script>
<HTML><HEAD><TITLE>Gallery Sample</TITLE></HEAD>
<BODY>
<DIV align=center>
<dotnet:Chart id="Chart" runat="server"/>
</DIV>
</BODY>
</BODY>
</HTML>
vb.net
<%@ Page Language="VB" Description="dotnetCHARTING Component"%>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<script runat="server">
Function getRandomData() As SeriesCollection
Dim SC As New SeriesCollection()
Dim myR As New Random()
Dim a As Integer
For a = 0 To 3
Dim s As New Series()
s.Name = "Series " & a
Dim b As Integer
For b = 0 To 4
Dim e As New Element()
e.Name = "E " & b
e.YValue = myR.Next(50)
s.Elements.Add(e)
Next b
SC.Add(s)
Next a
SC(0).DefaultElement.Color = Color.FromArgb(49, 255, 49)
SC(1).DefaultElement.Color = Color.FromArgb(255, 255, 0)
SC(2).DefaultElement.Color = Color.FromArgb(255, 99, 49)
SC(3).DefaultElement.Color = Color.FromArgb(0, 156, 255)
Return SC
End Function 'getRandomData
Sub Page_Load(sender As [Object], e As EventArgs)
' Set the title.
Chart.Title = "My Chart"
' Set the x axis label
Chart.ChartArea.XAxis.Label.Text = "X Axis Label"
' Set the y axis label
Chart.ChartArea.YAxis.Label.Text = "Y Axis Label"
' Set the directory where the images will be stored.
Chart.TempDirectory = "temp"
' Set the bar shading effect
Chart.ShadingEffect = True
' Set he chart size.
Chart.Size = "600x350"
' Add the random data.
Chart.SeriesCollection.Add(getRandomData())
End Sub 'Page_Load
</script>
<HTML><HEAD><TITLE>Gallery Sample</TITLE></HEAD>
<BODY>
<DIV align=center>
<dotnet:Chart id="Chart" runat="server"/>
</DIV>
</BODY>
</BODY>
</HTML>
破解版下载地址:http://files.cnblogs.com/dreamof/dotnetcharting.rar
使用手册可从官方网下载(E文):http://www.dotnetcharting.com
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。