简体   繁体   English

如何在Xtracharts devexpress中设置日期时间限制

[英]how to set limits for datetime in xtracharts devexpress

I am using a devexpress xtrachart in which in x-axis there is date. 我正在使用devexpress xtrachart,其中在x轴上有日期。 Now, the date in x-axis I am binding from database as: y-axis has values 现在,我从数据库绑定的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;

Now, the datetime in database is for today date and different hours like 现在,数据库中的日期时间是今天的日期和不同的时间,例如

在此处输入图片说明

but in chart its showing like below only one datetime: 但在图表中,它的显示如下仅一个日期时间: 在此处输入图片说明

How can i fix this, I just want it to show today's datetime(and time not as 00:00:00) That is if for today range in x-axis must be like: startdate in x-axis one hour before current datetime and enddate in x-axis one hour after current datetime or one hour difference 我该如何解决这个问题,我只希望它显示今天的日期时间(而不是00:00:00)就好像今天在x轴上的范围必须是这样:在x轴上的startdate在当前日期时间之前一小时,并且在当前日期时间之后一小时或相差一小时的x轴上的结束日期

example if current datetime is 2014-10-11 10:00:00 in x-axis it show like 2014-10-11 09:00:00 , 2014-10-11 10:00:00 , 2014-10-11 11:00:00 .. 例如,如果当前日期时间在x轴上为2014-10-11 10:00:00,则显示为2014-10-11 09:00:00,2014-10-11 10:00:00,2014-10-11 11 :00:00 ..

I tried VisualRange and WholeRange too but its not working. 我也尝试了VisualRange和WholeRange,但是它不起作用。

It's two step process show date and time in the scale: 这是两步过程,以刻度显示日期和时间:

  1. Set the Axis.DateTimeOptions.Format property to DateTimeFormat.General . Axis.DateTimeOptions.Format属性设置为DateTimeFormat.General
  2. Then Axis.DateTimeScaleOptions property with custom settings. 然后使用自定义设置的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; 

Currently Axis.DataTimeScaleOptions.GridAlignment and MeaureUnit property by default set to Day, so you are able to see the single data data with Aggregation operation(Sum etc). 当前Axis.DataTimeScaleOptions.GridAlignment和MeaureUnit属性默认设置为Day,因此您可以通过Aggregation操作(Sum等)查看单个数据数据。

Refer: 参考:
devexpress xtracharts showing date only devexpress xtracharts仅显示日期

I just want it to show today's datetime(and time not as 00:00:00) That is if for today range in x-axis must be like: startdate in x-axis one hour before current datetime and enddate in x-axis one hour after current date time or one hour difference 我只希望它显示今天的日期时间(而不是00:00:00),也就是说,今天的x轴范围必须是:当前日期之前一小时的x轴开始日期和x轴一的结束日期当前日期时间后一小时或一小时之间的时差

Try to tweak with Range properties, below is the just example snippet: 尝试调整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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM