1
votes

I am using a devexpress xtrachart in which in x-axis there is date. Now, the date in x-axis I am binding from database as: y-axis has values

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

enter image description here

but in chart its showing like below only one datetime: enter image description here

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

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 ..

I tried VisualRange and WholeRange too but its not working.

1
which version of dlls are you using. Visual Range and WholeRange are introduced separately in version 14.x. if you are using 13.x then WholeRange and ScrollRange are exist.Niranjan Singh
my version is 13.2.8.. in 13.2.8 VisualRange also present but I don't think these work for datetime. do they?Silver
surely work.. you just need to customize the Range property to just display 24 hours only.. you just need to specify it.Niranjan Singh

1 Answers

2
votes

It's two step process show date and time in the scale:

  1. Set the Axis.DateTimeOptions.Format property to DateTimeFormat.General.
  2. Then Axis.DateTimeScaleOptions property with custom settings.

    (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).

Refer:
devexpress xtracharts showing date only

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

Try to tweak with Range properties, below is the just example snippet:

DateTime start = DateTime.Today;
XYDiagram diagram = (XYDiagram)chartEditor.Diagram;

diagram.AxisX.WholeRange.Auto = false;
diagram.AxisX.VisualRange.SetMinMaxValues(start.AddHours(0), start.AddHours(24));