Web页面折线图事例(代码),带有控件!
支持直接绑定数据库
绑定数据库代码如下:
/// <summary>
/// This method is where you generate your graph.
/// </summary>
/// <param name="masterPane">You are provided with a MasterPane instance that
/// contains one GraphPane by default (accessible via masterPane[0]).</param>
/// <param name="g">A graphics instance so you can easily make the call to AxisChange()</param>
private void OnRenderGraph( ZedGraphWeb zgw, Graphics g, MasterPane masterPane )
{
// Get the GraphPane so we can work with it
GraphPane myPane = masterPane[0];

// Set the titles and axis labels
myPane.Title.Text = "访问统计折线图";
myPane.XAxis.Title.Text = "日期";
myPane.YAxis.Title.Text = "访问量";

// Create a new DataSourcePointList to handle the database connection
DataSourcePointList dspl = new DataSourcePointList();

// Specify the table as the data source
dspl.DataSource = GetData().Tables[0];
// The X data will come from the "Period" column
dspl.XDataMember = "datere";
// The Y data will come from the "Forecast" column
dspl.YDataMember = "countre";
// The Z data are not used
dspl.ZDataMember = null;

//dspl.TagDataMember = "DJA Holt's forecasting";

// Generate a blue curve with circle symbols, and "My Curve 2" in the legend
LineItem myCurve2 = myPane.AddCurve("My Curve 2", dspl, Color.Blue,
SymbolType.Circle);
// Fill the area under the curve with a white-red gradient at 45 degrees
myCurve2.Line.Fill = new Fill(Color.White, Color.Red, 45F);
// Make the symbols opaque by filling them with white
myCurve2.Symbol.Fill = new Fill(Color.White);

// Set the XAxis to date type
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.CrossAuto = true;

// Fill the axis background with a color gradient
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F);

masterPane.AxisChange(g);
}


protected DataSet GetData()
{
SqlConnection conn = new SqlConnection("server=.;database=hodovoddb;uid=sa;pwd=sa");
SqlDataAdapter da = new SqlDataAdapter("select countre,datere from t_BRowseRecord", conn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
事例及控件下载
/Files/tks/zedgraph_web_sample_v5.0.7.rar
支持直接绑定数据库
绑定数据库代码如下:
/// <summary>
/// This method is where you generate your graph.
/// </summary>
/// <param name="masterPane">You are provided with a MasterPane instance that
/// contains one GraphPane by default (accessible via masterPane[0]).</param>
/// <param name="g">A graphics instance so you can easily make the call to AxisChange()</param>
private void OnRenderGraph( ZedGraphWeb zgw, Graphics g, MasterPane masterPane )
{
// Get the GraphPane so we can work with it
GraphPane myPane = masterPane[0];
// Set the titles and axis labels
myPane.Title.Text = "访问统计折线图";
myPane.XAxis.Title.Text = "日期";
myPane.YAxis.Title.Text = "访问量";
// Create a new DataSourcePointList to handle the database connection
DataSourcePointList dspl = new DataSourcePointList();
// Specify the table as the data source
dspl.DataSource = GetData().Tables[0];
// The X data will come from the "Period" column
dspl.XDataMember = "datere";
// The Y data will come from the "Forecast" column
dspl.YDataMember = "countre";
// The Z data are not used
dspl.ZDataMember = null;
//dspl.TagDataMember = "DJA Holt's forecasting";
// Generate a blue curve with circle symbols, and "My Curve 2" in the legend
LineItem myCurve2 = myPane.AddCurve("My Curve 2", dspl, Color.Blue,
SymbolType.Circle);
// Fill the area under the curve with a white-red gradient at 45 degrees
myCurve2.Line.Fill = new Fill(Color.White, Color.Red, 45F);
// Make the symbols opaque by filling them with white
myCurve2.Symbol.Fill = new Fill(Color.White);
// Set the XAxis to date type
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.CrossAuto = true;
// Fill the axis background with a color gradient
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F);
masterPane.AxisChange(g);
}

protected DataSet GetData()
{
SqlConnection conn = new SqlConnection("server=.;database=hodovoddb;uid=sa;pwd=sa");
SqlDataAdapter da = new SqlDataAdapter("select countre,datere from t_BRowseRecord", conn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}事例及控件下载
/Files/tks/zedgraph_web_sample_v5.0.7.rar


浙公网安备 33010602011771号