我期望的效果:就是X轴显示日期时间,Y轴显示正整数,让图表表示数值随时间的变化情况。但是官方给定的Demo的X轴是数字,我写了个小例子,发现直接传DateTime类型的数组给C1Chart,但是图表并没有如期的被绘制。请问如何实现上述效果呢?
我写的小Demo的代码是:
1,创建一个winform程序(2.0的)
2,放置一个C1Chart,命名为offlineChart。
3,修改了ChartArea的AxisX的AnnoFormat为DateGeneral。
4,全部代码如下:
- using System;
- using System.Windows.Forms;
- using C1.Win.C1Chart;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- ChartDataSeries cdsTemp;
- DateTime[] x = new DateTime[100];
- double[] y = new double[100];
- private void Form1_Load(object sender, EventArgs e)
- {
- // Create chart series
- offlineChart.ChartGroups[0].ChartData.SeriesList.Clear();
- cdsTemp = offlineChart.ChartGroups[0].ChartData.SeriesList.AddNewSeries();
- offlineChart.UseAntiAliasedGraphics = true;
- offlineChart.UseAntiAliasedText = true;
- for (int i = 0; i < 100; i++)
- {
- x[i] = DateTime.Now.AddMinutes(1);
- y[i] = i;
- }
- // Copy data arrays into c1Chart
- offlineChart.ChartArea.AxisX.Max = x.Length - 1;
- offlineChart.ChartArea.AxisX.ScrollBar.Max = x.Length - 1;
- cdsTemp.Y.CopyDataIn(y);
- cdsTemp.X.CopyDataIn(x);
- }
- }
- }
复制代码 |
|