今天加班文档整理完写下这篇博客,不好的地方大家提提意见。 我也是新手啊。
下面我先发一个3D柱形统计图
首先 把数据库代码发上来省的大家建表
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AAAAgrade]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[AAAAgrade]( [name] [varchar](50) NULL, [id] [int] NOT NULL, [grade] [int] NULL, [source] [int] NULL, CONSTRAINT [PK_AAAAgrade] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END
第一步:先把 <asp:Literal ID="Literal1" runat="server"></asp:Literal> 拖入前端页面
第二步: 后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using InfoSoftGlobal; namespace Statistics { public partial class Default : System.Web.UI.Page { private string conectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Charts"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { this.Literal1.Text = GetGradeStat(); } /// <summary> /// 根据xml格式把数据显示到页面 /// </summary> /// <returns></returns> public string GetGradeStat() { string strXML; strXML = "<graph caption='考试分数对比' xAxisName='姓名' yAxisName='成绩' decimalPrecision='0' formatNumberScale='1' palette='4'>"; //strXML = strXML + "<categories>"; //name表数据 SqlConnection con = new SqlConnection(conectionString); con.Open(); SqlDataAdapter adapter = new SqlDataAdapter("select name from AAAAgrade",con); DataSet ds = new DataSet(); adapter.Fill(ds,"name"); DataTable dt = ds.Tables["name"]; //grade表数据 SqlDataAdapter adapter1 = new SqlDataAdapter("select grade from AAAAgrade", con); adapter1.Fill(ds, "grade"); DataTable dt2 = ds.Tables["grade"]; //for (int j = 0; j < dt2.Rows.Count; j++) //{ // strXML = strXML + "<set value='" + dt2.Rows[j][0].ToString() + "'/>"; //} for (int i = 0; i < dt.Rows.Count; i++) { strXML = strXML + "<set name='" + dt.Rows[i][0].ToString() + "' value='" + dt2.Rows[i][0].ToString() + "' />"; } //strXML = strXML + "</categories> "; strXML = strXML + "</graph>"; return FusionCharts.RenderChart("FusionCharts/Column3D.swf", "Default.aspx", strXML, "myNext", "750", "300", false, false); } } }
如下图柱形
这就完成了柱形统计》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》。。。
二、、
在发给双线图 首先前端还是微软的Literal控件
然后后端代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using InfoSoftGlobal; namespace Statistics { public partial class Default4 : System.Web.UI.Page { private string conectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Charts"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { this.Literal1.Text = GetGradeStat(); } /// <summary> /// 根据xml格式把数据显示到页面 /// </summary> /// <returns></returns> public string GetGradeStat() { string strXML; strXML = "<chart caption='考试分数对比' xAxisName='姓名' yAxisName='成绩' decimalPrecision='0' formatNumberScale='1' palette='4' showLabels='1' showColumnShadow='1' animation='1' showAlternateHGridColor='1' AlternateHGridColor='ff5904' divLineColor='ff5904' divLineAlpha='20' alternateHGridAlpha='5' canvasBorderColor='666666' baseFontColor='666666' lineColor='FF5904' lineAlpha='85' showValues='1' rotateValues='1' valuePosition='auto' canvaspadding='8'>"; strXML = strXML + "<categories>"; //name字段数据 SqlConnection con = new SqlConnection(conectionString); con.Open(); SqlDataAdapter adapter = new SqlDataAdapter("select name from AAAAgrade", con); DataSet ds = new DataSet(); adapter.Fill(ds, "name"); DataTable dt = ds.Tables["name"]; for (int i = 0; i < dt.Rows.Count; i++) { strXML = strXML + "<category label='" + dt.Rows[i][0].ToString() + "' isSliced='0'/>"; } strXML = strXML + "</categories><dataset seriesName='Model A12' color='A66EDD' > "; //grade字段数据 SqlDataAdapter adapter1 = new SqlDataAdapter("select grade from AAAAgrade", con); adapter1.Fill(ds, "grade"); DataTable dt2 = ds.Tables["grade"]; for (int j = 0; j < dt2.Rows.Count; j++) { strXML = strXML + "<set value='" + dt2.Rows[j][0].ToString() + "'/>"; } strXML = strXML + "</dataset><dataset seriesName='Model A15' color='F6BD0F'>"; //source字段数据 SqlDataAdapter adapter2 = new SqlDataAdapter("select source from AAAAgrade", con); adapter2.Fill(ds, "source"); DataTable dt3 = ds.Tables["source"]; for (int d = 0; d< dt3.Rows.Count; d++) { strXML = strXML + "<set value='" + dt3.Rows[d][0].ToString() + "'/>"; } strXML = strXML + "</dataset>"; strXML = strXML + "</chart>"; return FusionCharts.RenderChart("FusionCharts/MSLine.swf", "Default.aspx", strXML, "myNext", "750", "300", false, false); } } }
如下图
其它数据统计可以下载FusionCharts 就可以完成呢。。。。。。。。。