c#chart 的x轴怎么设置时间形式,是从0开始的计时,试了很多,没试出来。请求指点
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Q695236
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Random rnd = new Random();
var data = Enumerable.Range(0, 10).Select((x, i) => rnd.NextDouble() + x * 0.6).ToList();
var t = Enumerable.Range(0, 10).Select(x => x * 30).Select(x => new { h = x / 3600, m = (x % 3600) / 60, s = (x % 3600) % 60 })
.Select(x => new DateTime(1900, 1, 1, x.h, x.m, x.s, DateTimeKind.Local)).ToList();
chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[0].XValueType = ChartValueType.Time;
chart1.Series[0].YValueType = ChartValueType.Double;
chart1.Series[0].Points.DataBindXY(t, data);
}
}
}
我的系统是英文的所以是 12:00AM,中文时间格式应该是 0:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Q695236
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<double> data;
List<DateTime> t;
Random rnd;
private void Form1_Load(object sender, EventArgs e)
{
rnd = new Random();
data = Enumerable.Range(0, 20).Select((x, i) => rnd.NextDouble() + x * 0.6).ToList();
t = Enumerable.Range(0, 20).Select(x => x * 30).Select(x => new { h = x / 3600, m = (x % 3600) / 60, s = (x % 3600) % 60 })
.Select(x => new DateTime(1900, 1, 1, x.h, x.m, x.s, DateTimeKind.Local)).ToList();
chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[0].XValueType = ChartValueType.Time;
chart1.Series[0].YValueType = ChartValueType.Double;
chart1.Series[0].Points.DataBindXY(t, data);
}
private void timer1_Tick(object sender, EventArgs e)
{
t.RemoveAt(0);
t.Add(t.Last().AddSeconds(30));
data.RemoveAt(0);
data.Add(rnd.NextDouble() * 2 - 1.0 + data.Last());
chart1.Series[0].Points.DataBindXY(t, data);
}
}
}