[英]VS2013 Dynamically create chart c#
無法創建標准圖表。 我嘗試了以下方法: http : //timbar.blogspot.com/2012/04/creating-chart-programmatically-in-c.html
例如代碼:
private void Form2_Load(object sender, EventArgs e)
{
var xvals = new[]
{
new DateTime(2012, 4, 4),
new DateTime(2012, 4, 5),
new DateTime(2012, 4, 6),
new DateTime(2012, 4, 7)
};
var yvals = new[] { 1,3,7,12 };
// create the chart
var chart = new Chart();
chart.Size = new Size(600, 250);
var chartArea = new ChartArea();
chartArea.AxisX.LabelStyle.Format = "dd/MMM\nhh:mm";
chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 8);
chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 8);
chart.ChartAreas.Add(chartArea);
var series = new Series();
series.Name = "Series1";
series.ChartType = SeriesChartType.FastLine;
series.XValueType = ChartValueType.DateTime;
chart.Series.Add(series);
// bind the datapoints
chart.Series["Series1"].Points.DataBindXY(xvals, yvals);
// copy the series and manipulate the copy
chart.DataManipulator.CopySeriesValues("Series1", "Series2");
chart.DataManipulator.FinancialFormula(
FinancialFormula.WeightedMovingAverage,
"Series2"
);
chart.Series["Series2"].ChartType = SeriesChartType.FastLine;
// draw!
chart.Invalidate();
}
但這給了我空的形式。
如何創建圖表? 請幫忙!
您需要將圖表添加到表單中:
this.Controls.Add(圖表);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.