在這里,就用DataTable做個例子
//表結構
DataTable newdtb = new DataTable();
newdtb.Columns.Add("Id", typeof(int));
newdtb.Columns.Add("ProName", typeof(string));
newdtb.Columns.Add("ProPrice", typeof(decimal));
newdtb.Columns.Add("Trade_Date", typeof(string));
newdtb.Columns["Id"].AutoIncrement = true;
//表記錄
Random ran = new Random();
for (int i = 1; i < 10; i++)
{
int RandKey = ran.Next(10, 9999);//10~9999之間的數
decimal dBase = Convert.ToDecimal(ran.NextDouble());//0~1之間的任意數
DataRow newRow = newdtb.NewRow();
newRow["Trade_Date"] = i.ToString() + "月";
newRow["ProPrice"] = Convert.ToDecimal((RandKey * dBase).ToString("0.0#"));
newdtb.Rows.Add(newRow);
}
this.chartControl1.Series.Clear();
//新建Series
Series sr = new Series("資金統計", ViewType.Line);//名稱與圖標的類型
//設置Series樣式
sr.ArgumentScaleType = ScaleType.Qualitative;//定性的
sr.ValueScaleType = ScaleType.Numerical;//數字類型
sr.PointOptions.PointView = PointView.ArgumentAndValues;//顯示表示的信息和數據
sr.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;//用百分比表示
sr.PointOptions.ValueNumericOptions.Precision = 0;//百分號前面的數字不跟小數點
//綁定數據源
sr.DataSource = newdtb.DefaultView;//newdtb是獲取到的數據(可以是數據庫中的表,也可以是DataTable)
sr.ArgumentDataMember = "Trade_Date";//綁定的文字信息(名稱)(坐標橫軸)
sr.ValueDataMembers[0] = "ProPrice";//綁定的值(數據)(坐標縱軸)
//樣式
sr.View.Color = Color.Red;//顏色
//添加到統計圖上
this.chartControl1.Series.Add(sr);
//圖例設置
SimpleDiagram3D diagram = new SimpleDiagram3D();
diagram.RuntimeRotation = true;
diagram.RuntimeScrolling = true;
diagram.RuntimeZooming = true;
//設置圖表標題
ChartTitle ct = new ChartTitle();
ct.Text = "神馬公司資金統計圖";
ct.TextColor = Color.Black;//顏色
ct.Font = new Font("Tahoma", 12);//字體
ct.Dock = ChartTitleDockStyle.Top;//停靠在上方
ct.Alignment = StringAlignment.Center;//居中顯示
this.chartControl1.Titles.Add(ct);
chartControl1.Legend.Visible = true;//不現實指示圖
效果實現后: