如何在xtracharts devexpress中设置datetime的限制

时间:2014-10-14 13:08:56

标签: c# charts devexpress

我正在使用devexpress xtrachart,其中x轴有日期。 现在, x轴上的日期我从数据库绑定为: y轴具有值

chartControl1.DataSource=dt;//used datatable
chartControl1.SeriesDataMember = "VariableName";
chartControl1.SeriesTemplate.ArgumentDataMember = "LastTime";
chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "LastValue" });
chartControl1.SeriesTemplate.ChangeView(ViewType.Line);
((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).AxisX.Label.DateTimeOptions.Format = DateTimeFormat.General;

现在,数据库中的日期时间是今天的日期和不同的时间,如

enter image description here

但在图表中,它只显示一个日期时间: enter image description here

我如何解决这个问题,我只想让它显示今天的日期时间(时间不是00:00:00) 那就是今天x轴的范围必须如下: 在当前日期时间前一小时在x轴上开始,在当前日期时间后一小时在x轴上结束 或一小时差异

示例如果当前日期时间是2014-10-11 10:00:00 在x轴显示它 2014-10-11 09:00:00,2014-10-11 10:00:00,2014-10-11 11:00:00 ..

我也尝试过VisualRange和WholeRange,但它无效。

1 个答案:

答案 0 :(得分:2)

这是两个步骤显示日期和时间的比例:

  1. Axis.DateTimeOptions.Format属性设置为DateTimeFormat.General
  2. 然后使用自定义设置的Axis.DateTimeScaleOptions属性。

    (XYDiagram)chartControl1.Diagram).AxisX.DateTimeOptions.Format = DateTimeFormat.General;
    (XYDiagram)chartControl1.Diagram).AxisX.DateTimeScaleOptions.GridAlignment = 
                                    DevExpress.XtraCharts.DateTimeGridAlignment.Minute;
    (XYDiagram)chartControl1.Diagram).AxisX.DateTimeScaleOptions.MeasureUnit = 
                                      DevExpress.XtraCharts.DateTimeMeasureUnit.Minute;
    
  3. 当前Axis.DataTimeScaleOptions.GridAlignment和MeaureUnit属性默认设置为Day,因此您可以通过聚合操作(Sum等)查看单个数据数据。

    参见:
    devexpress xtracharts showing date only

      

    我只是希望它显示今天的日期时间(时间不是00:00:00)   也就是说,如果今天x轴的范围必须像:x轴的startdate   在当前日期时间之前一小时,在x轴之后一小时结束   当前日期时间或一小时差异

    尝试使用Range属性进行调整,下面只是示例代码段:

    DateTime start = DateTime.Today;
    XYDiagram diagram = (XYDiagram)chartEditor.Diagram;
    
    diagram.AxisX.WholeRange.Auto = false;
    diagram.AxisX.VisualRange.SetMinMaxValues(start.AddHours(0), start.AddHours(24));