顺便附上我的后台代码~
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 System.Drawing;
using System.Web.UI.DataVisualization.Charting;
namespace zhu
{
public partial class WebForm3 : System.Web.UI.Page
{
public SqlConnection SqlConnString2;
string[] Count3 = new string[9];
double[] Count4 = new double[9];
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds2 = new DataSet();
string vOutParam = "";
//载入SQL server的查询存储过程
ds2 = ExeProcDT4("Searchtable6", "", ref vOutParam);
if (ds2.Tables.Count > 0)
{
DataTable dt2 = new DataTable();
dt2 = ds2.Tables[0];
if (dt2.Rows.Count > 0)
{
for (int i = 0; i < 9; i++)
{
Count4[i] = Convert.ToDouble(dt2.Rows[i]["PM"]);
Count3[i] = dt2.Rows[i]["d"].ToString() + dt2.Rows[i]["e"].ToString();
}
}
}
zhuzhaugntu2(Count3, Count4);
}
//柱状图设置
protected void zhuzhaugntu2(string[] a, double[] b)
{
Chart1.ChartAreas[0].BackColor = Color.Black;//设置背景为黑色
Chart1.ChartAreas[0].Area3DStyle.PointGapDepth = 10;//x轴行间距
Chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;//需线
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Yellow;//需线颜色
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//关掉竖线1
//根据水尺最高值设置Y轴间距
Chart1.ChartAreas[0].AxisY.Maximum = 10000;
Chart1.Series[0].Label = "#VAL";//设置标签文本 (在设计期通过属性窗口编辑更直观)
Chart1.Series[0].IsValueShownAsLabel = true;//显示标签
Chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Blue;
Chart1.ChartAreas[0].AxisX.LabelAutoFitMaxFontSize = 12;
Chart1.ChartAreas[0].AxisY.LabelAutoFitMaxFontSize = 15;
Chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Red;
Chart1.Series[0].Points.DataBindXY(a, b);//初始化数据
}
//连接数据库
private SqlConnection GetConnect()
{
string strSqlSqlConn2 = "Data Source=.;Initial Catalog=plc;" +
"Persist Security Info=True;User ID=Jerome;Password=123456";
SqlConnection sqlConnString2 = new SqlConnection(strSqlSqlConn2);
sqlConnString2.Open();
return sqlConnString2;
}
public DataSet ExeProcDT4(string procName, string vInParam, ref string vOutParam)
{
SqlConnString2 = GetConnect();
SqlCommand SqlCmd = new SqlCommand(procName, SqlConnString2);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@inparam", SqlDbType.VarChar, 1000).Value = vInParam;
SqlCmd.Parameters.Add("@outparam", SqlDbType.VarChar, 1024).Direction = ParameterDirection.Output;
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCmd);
DataSet DS = new DataSet();
SqlDa.Fill(DS);
vOutParam = SqlCmd.Parameters["@outparam"].Value.ToString();
return DS;
}
}
}