C#_MS_CHART_控件使用方法汇总(附统计图)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
OleDbCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "select 序号 from pub_log_read order by 序号 asc"; //DataSet ds = new DataSet(); //OleDbDataAdapter da = new OleDbDataAdapter(); //da.SelectCommand = cmd; //da.Fill(ds, "tbscore");
数据库4,只绑定y Chart1.Series.Clear(); Chart1.Series.Add("序号"); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
很多点,效率还可以 // Fill series data
double yValue = 50.0; Random random = new Random(); for (int pointIndex = 0; pointIndex < 20000;pointIndex++) {
yValue = yValue + (random.NextDouble() * 10.0 - 5.0); Chart1.Series["Series1"].Points.AddY(yValue); } // Set fast line chart type Chart1.Series["Series1"].ChartType = SeriesChartType.FastLine;
显示 column 类型图,柱状图 // Create new data series and set it's visual attributes Chart1.Series.Clear();
Series series = new Series("FlowRead"); series.ChartType = SeriesChartType.Column; series.BorderWidth = 3; series.ShadowOffset = 2; // Populate new series with data series.Points.AddY(67); series.Points.AddY(57); series.Points.AddY(83); series.Points.AddY(23);
OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Chart1.DataBindTable(dr, "账号"); dr.Close();
数据库绑定3-string-int型 Chart1.Series.Clear(); Chart1.Series.Add("Series1"); OleDbConnection conn = new
Chart1.DataSource = ds;
Chart1.Series["Series1"].XValueMember = "账号"; Chart1.Series["Series1"].YValueMembers = "次数"; // Data bind to the selected data source Chart1.DataBind(); conn.Close();
OleDbCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "select 账号,count(账号) as 次数 from pub_log_read group by 账号 order by 账号 asc"; //DataSet ds = new DataSet(); //OleDbDataAdapter da = new OleDbDataAdapter(); //da.SelectCommand = cmd; //da.Fill(ds, "tbscore");
c# ms chart 控件使用方法
第一个简单的chart:创建曲线图 chart1.Series.Clear(); Series series = new Series("Spline"); series.ChartType = SeriesChartType.Spline; series.BorderWidth = 3; series.ShadowOffset = 2; // Populate new series with data series.Points.AddY(67); series.Points.AddY(57); series.Points.AddY(83); series.Points.AddY(23); series.Points.AddY(70); series.Points.AddY(60); series.Points.AddY(90); series.Points.AddY(20); // Add series into the chart's series collection chart1.Series.Add(series);
// Add 1 day to our X value date = date.AddDays(1);
}源自文库
int-int 的 xy 数据绘图 // Create a new random number generator
Random rnd = new Random();
// Add points to the stock chart series
}
日期,xy 类型 // Create a new random number generator
Random rnd = new Random();
// Data points X value is using current date DateTime date = DateTime.Now.Date;
// Set series chart type Chart1.Series["Series1"].ChartType = SeriesChartType.Line; Chart1.Series["Series2"].ChartType = SeriesChartType.Spline;
// Set point labels Chart1.Series["Series1"].IsValueShownAsLabel = true; Chart1.Series["Series2"].IsValueShownAsLabel = true; // Enable X axis margin Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; // Enable 3D, and show data point marker lines Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; Chart1.Series["Series1"]["ShowMarkerLines"] = "True"; Chart1.Series["Series2"]["ShowMarkerLines"] = "True";
cmd.CommandText = "select 账号,count(账号) as 次数 from pub_log_read group by 账号 order by 账号 asc";
conn.Open();
DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = cmd; da.Fill(ds, "tbscore");
同时显示 2 条曲线 // Populate series with random data
Random random = new Random(); for (int pointIndex = 0; pointIndex < 10;pointIndex++) {
Chart1.Series["Series1"].Points.AddY(random.Next(45, 95)); Chart1.Series["Series2"].Points.AddY(random.Next(5, 75)); }
for (int index = 0; index < 10; index++)
{
Chart1.Series["Series1"].Points.AddXY(
rnd.Next(10,90),
// X value is a date
rnd.Next(40,50)); //Close Y value
}
数据库数据2,string-int类型 Chart1.Series.Clear(); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
OleDbCommand cmd = conn.CreateCommand();
数据库数据,datetime-int类型 Chart1.Series.Clear(); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
// Add points to the stock chart series
for (int index = 0; index < 10; index++)
{
Chart1.Series["Series1"].Points.AddXY(
date,
// X value is a date
rnd.Next(40,50)); //Close Y value
series.Points.AddY(70); series.Points.AddY(60); series.Points.AddY(90); series.Points.AddY(20); // Add series into the chart's series collection Chart1.Series.Add(series);
OleDbCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "select 时间,序号 from pub_log_read order by 序号 asc"; //DataSet ds = new DataSet(); //OleDbDataAdapter da = new OleDbDataAdapter(); //da.SelectCommand = cmd; //da.Fill(ds, "tbscore"); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Chart1.DataBindTable(dr, "时间"); dr.Close();
数据库4,只绑定y Chart1.Series.Clear(); Chart1.Series.Add("序号"); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
很多点,效率还可以 // Fill series data
double yValue = 50.0; Random random = new Random(); for (int pointIndex = 0; pointIndex < 20000;pointIndex++) {
yValue = yValue + (random.NextDouble() * 10.0 - 5.0); Chart1.Series["Series1"].Points.AddY(yValue); } // Set fast line chart type Chart1.Series["Series1"].ChartType = SeriesChartType.FastLine;
显示 column 类型图,柱状图 // Create new data series and set it's visual attributes Chart1.Series.Clear();
Series series = new Series("FlowRead"); series.ChartType = SeriesChartType.Column; series.BorderWidth = 3; series.ShadowOffset = 2; // Populate new series with data series.Points.AddY(67); series.Points.AddY(57); series.Points.AddY(83); series.Points.AddY(23);
OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Chart1.DataBindTable(dr, "账号"); dr.Close();
数据库绑定3-string-int型 Chart1.Series.Clear(); Chart1.Series.Add("Series1"); OleDbConnection conn = new
Chart1.DataSource = ds;
Chart1.Series["Series1"].XValueMember = "账号"; Chart1.Series["Series1"].YValueMembers = "次数"; // Data bind to the selected data source Chart1.DataBind(); conn.Close();
OleDbCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "select 账号,count(账号) as 次数 from pub_log_read group by 账号 order by 账号 asc"; //DataSet ds = new DataSet(); //OleDbDataAdapter da = new OleDbDataAdapter(); //da.SelectCommand = cmd; //da.Fill(ds, "tbscore");
c# ms chart 控件使用方法
第一个简单的chart:创建曲线图 chart1.Series.Clear(); Series series = new Series("Spline"); series.ChartType = SeriesChartType.Spline; series.BorderWidth = 3; series.ShadowOffset = 2; // Populate new series with data series.Points.AddY(67); series.Points.AddY(57); series.Points.AddY(83); series.Points.AddY(23); series.Points.AddY(70); series.Points.AddY(60); series.Points.AddY(90); series.Points.AddY(20); // Add series into the chart's series collection chart1.Series.Add(series);
// Add 1 day to our X value date = date.AddDays(1);
}源自文库
int-int 的 xy 数据绘图 // Create a new random number generator
Random rnd = new Random();
// Add points to the stock chart series
}
日期,xy 类型 // Create a new random number generator
Random rnd = new Random();
// Data points X value is using current date DateTime date = DateTime.Now.Date;
// Set series chart type Chart1.Series["Series1"].ChartType = SeriesChartType.Line; Chart1.Series["Series2"].ChartType = SeriesChartType.Spline;
// Set point labels Chart1.Series["Series1"].IsValueShownAsLabel = true; Chart1.Series["Series2"].IsValueShownAsLabel = true; // Enable X axis margin Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; // Enable 3D, and show data point marker lines Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; Chart1.Series["Series1"]["ShowMarkerLines"] = "True"; Chart1.Series["Series2"]["ShowMarkerLines"] = "True";
cmd.CommandText = "select 账号,count(账号) as 次数 from pub_log_read group by 账号 order by 账号 asc";
conn.Open();
DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = cmd; da.Fill(ds, "tbscore");
同时显示 2 条曲线 // Populate series with random data
Random random = new Random(); for (int pointIndex = 0; pointIndex < 10;pointIndex++) {
Chart1.Series["Series1"].Points.AddY(random.Next(45, 95)); Chart1.Series["Series2"].Points.AddY(random.Next(5, 75)); }
for (int index = 0; index < 10; index++)
{
Chart1.Series["Series1"].Points.AddXY(
rnd.Next(10,90),
// X value is a date
rnd.Next(40,50)); //Close Y value
}
数据库数据2,string-int类型 Chart1.Series.Clear(); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
OleDbCommand cmd = conn.CreateCommand();
数据库数据,datetime-int类型 Chart1.Series.Clear(); OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\db.mdb" + ";Persist Security Info=False");
// Add points to the stock chart series
for (int index = 0; index < 10; index++)
{
Chart1.Series["Series1"].Points.AddXY(
date,
// X value is a date
rnd.Next(40,50)); //Close Y value
series.Points.AddY(70); series.Points.AddY(60); series.Points.AddY(90); series.Points.AddY(20); // Add series into the chart's series collection Chart1.Series.Add(series);
OleDbCommand cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "select 时间,序号 from pub_log_read order by 序号 asc"; //DataSet ds = new DataSet(); //OleDbDataAdapter da = new OleDbDataAdapter(); //da.SelectCommand = cmd; //da.Fill(ds, "tbscore"); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Chart1.DataBindTable(dr, "时间"); dr.Close();