none
在WPF中应用MSChart的Rangebar进行绘图,绘制完后,横坐标显示的默认为日期,却不是具体的时间,怎样才能显示时间 RRS feed

  • 问题

  •   C#我在WPF中应用MSChart的Rangebar进行绘图,绘制完后,横坐标显示的默认为日期,不是具体的时间,请问怎么设置才能显示时间到分钟。

      网上看到说是用 XValueType属性,只是不知道在程序中怎么用,我写成 series1.XValueType=“DateTime”,提示错误,dateTime不能作为 datetime时类型,不能当变量使用。

    代码如下:

    ChartArea ca = new ChartArea("Default");
                //ca.Area3DStyle.Enable3D = true;   //是否绘制3D图
                this.GanttChart.ChartAreas.Add(ca);

                //创建图注
                Legend legend = new Legend("my Legend");
                GanttChart.Legends.Add(legend);

                //新建曲线
                Series Series1 = new Series("Series1");
                Series1.ChartType = SeriesChartType.RangeBar;
                //Series1.IsValueShownAsLabel = true;
                Series1.LegendText = "加工作业";
                Series1.IsXValueIndexed = true;

                this.GanttChart.Series.Add(Series1);

                //数据添加
                //GanttChart.Series["Series1"].ChartType = SeriesChartType.RangeBar;
                DateTime currentData = DateTime.Now;
                GanttChart.Series["Series1"].Points.AddXY(1, currentData, currentData.AddMinutes(50));
                GanttChart.Series["Series1"].Points.AddXY(2, currentData.AddMinutes(10), currentData.AddMinutes(100));
                GanttChart.Series["Series1"].Points.AddXY(3, currentData.AddMinutes(110), currentData.AddMinutes(130));
                GanttChart.Series["Series1"].Points.AddXY(1, currentData.AddMinutes(110), currentData.AddMinutes(150));
                GanttChart.Series["Series1"].Points.AddXY(4, currentData.AddMinutes(15), currentData.AddMinutes(120));
                GanttChart.Series["Series1"].Points.AddXY(2, currentData.AddMinutes(120), currentData.AddMinutes(180));
           
                GanttChart.Series["Series1"].Points[0].AxisLabel = "Task 1";
                GanttChart.Series["Series1"].Points[1].AxisLabel = "Task 2";
                GanttChart.Series["Series1"].Points[2].AxisLabel = "Task 3";
                GanttChart.Series["Series1"].Points[4].AxisLabel = "Task 4";

                GanttChart.Series["Series1"]["PointWidth"] = "0.3";

    2012年6月26日 1:45

全部回复