WinForm 下面用 System.Windows.Forms.DataVisualization.Charting.Chart:
代码:
public Form1()
{
InitializeComponent();
var serieItem = this.chart1.Series[0];
serieItem.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar;
serieItem.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
serieItem.IsValueShownAsLabel = true;
serieItem.IsXValueIndexed = true;
serieItem.LabelAngle = 10;
DataTable table = GetDataSource();
DataPoint pointItem = null;
for (int i = 0; i < table.Rows.Count; i++)
{
pointItem = new DataPoint();
pointItem.SetValueXY(table.Rows[i]["TimeValue"], table.Rows[i]["Value"]);
pointItem.AxisLabel = table.Rows[i]["Value"].ToString();
serieItem.Points.Add(pointItem);
}
}
DataTable GetDataSource()
{
DataTable table = new DataTable();
table.Columns.Add("Value", typeof(double));
table.Columns.Add("TimeValue", typeof(DateTime));
DataRow row = table.NewRow();
row["Value"] = 45;
row["TimeValue"] = DateTime.Parse("2010-08-08 9:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 50;
row["TimeValue"] = DateTime.Parse("2010-08-08 10:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 55;
row["TimeValue"] = DateTime.Parse("2010-08-08 10:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 45;
row["TimeValue"] = DateTime.Parse("2010-08-08 11:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 52;
row["TimeValue"] = DateTime.Parse("2010-08-08 11:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 43;
row["TimeValue"] = DateTime.Parse("2010-08-08 12:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 60;
row["TimeValue"] = DateTime.Parse("2010-08-08 12:30");
table.Rows.Add(row);
return table;
}
WebForm 下面用 System.Web.UI.DataVisualization.Charting.Chart:
代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var serieItem = this.Chart1.Series[0];
serieItem.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeBar;
serieItem.XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Time;
serieItem.IsValueShownAsLabel = true;
serieItem.IsXValueIndexed = true;
serieItem.LabelAngle = 10;
DataTable table = GetDataSource();
DataPoint pointItem = null;
for (int i = 0; i < table.Rows.Count; i++)
{
pointItem = new DataPoint();
pointItem.SetValueXY(table.Rows[i]["TimeValue"], table.Rows[i]["Value"]);
pointItem.AxisLabel = table.Rows[i]["Value"].ToString();
serieItem.Points.Add(pointItem);
}
}
}
DataTable GetDataSource()
{
DataTable table = new DataTable();
table.Columns.Add("Value", typeof(double));
table.Columns.Add("TimeValue", typeof(DateTime));
DataRow row = table.NewRow();
row["Value"] = 45;
row["TimeValue"] = DateTime.Parse("2010-08-08 9:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 50;
row["TimeValue"] = DateTime.Parse("2010-08-08 10:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 55;
row["TimeValue"] = DateTime.Parse("2010-08-08 10:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 45;
row["TimeValue"] = DateTime.Parse("2010-08-08 11:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 52;
row["TimeValue"] = DateTime.Parse("2010-08-08 11:30");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 43;
row["TimeValue"] = DateTime.Parse("2010-08-08 12:00");
table.Rows.Add(row);
row = table.NewRow();
row["Value"] = 60;
row["TimeValue"] = DateTime.Parse("2010-08-08 12:30");
table.Rows.Add(row);
return table;
}
可以看出两种控件的代码没大区别、就命名空间不同。
什么图形,可以用控件,或者自己根据数据画图输出。
请问这个东西是不是要装了vs2008 sp1版才能用啊,我要装sp1时需要C盘 空间5G多,而我空间不够 ,只有3G多,现在只装了vs2008,怎么办,我需要这个功能