新建一个空的winform项目测试,拖入两个flex chart
代码如下:
- public partial class Form1 : Form
- {
- public Form1()
- {
-
- InitializeComponent();
- LoadData();
- }
- public void LoadData()
- {
- List<DataItem> points = new List<DataItem>();
- DateTime now = DateTime.Now;
- DateTime begintime = now;
- DateTime endtime = now;
- var rand = new Random();
- for (int i = 0; i < 1000; i++)
- {
- endtime = now.AddSeconds(i);
- points.Add(new DataItem()
- {
- Date = endtime,
- Series1 = rand.NextDouble() * 10
- });
- }
- var chart = flexChart1;
- chart.ChartType = ChartType.Line;
- chart.BeginUpdate();
- chart.DataSource = points.ToArray();
- chart.Series.Clear();
- chart.BindingX = "Date";
- chart.Series.Add(new Series() { Name = "Series1", Binding = "Series1" });
- chart.Series[0].Style.Stroke = Brushes.Red;
- chart.Series[0].Style.StrokeWidth = 1;
- chart.AxisX.Min = begintime.ToOADate();
- chart.AxisX.Max = endtime.ToOADate();
- chart.EndUpdate();
- var RangeSelectChart = flexChart2;
- RangeSelectChart.Legend.Position = Position.None;
- RangeSelectChart.ChartType = ChartType.Line;
- RangeSelectChart.Series.Clear();
- RangeSelectChart.BindingX = "Date";
- RangeSelectChart.Series.Add(new Series() { Name = "Series1", Binding = "Series1" });
- RangeSelectChart.Series[0].Style.Stroke = Brushes.Red;
- RangeSelectChart.Series[0].Style.StrokeWidth = 1;
- RangeSelectChart.DataSource = points.ToArray();
- RangeSelector XRangeSelector;
- XRangeSelector = new RangeSelector(flexChart1);
- XRangeSelector.LowerValue = begintime.ToOADate();
- XRangeSelector.UpperValue = endtime.ToOADate();
- }
- class DataItem
- {
- public double Series1 { get; set; }
- public DateTime Date { get; set; }
- }
- }
复制代码 |
|