qq_34617392 2018-07-20 01:48 采纳率: 33.3%
浏览 6981
已结题

c#chart 的x轴怎么设置时间形式,是从0开始的计时

c#chart 的x轴怎么设置时间形式,是从0开始的计时,试了很多,没试出来。请求指点

  • 写回答

4条回答 默认 最新

  • threenewbee 2018-07-20 02:16
    关注
     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);
            }
        }
    }
    
    
    评论

报告相同问题?