User (Old forums)MemberOctober 21, 2008 at 1:36 pmPost count: 23064
I’ve looked through the forum and the chart explorer and I’m still not quite sure how best to accomplish what I need to do.
Basically I have a few data points coming in to my system. I don’t care about the absolute date and time for the point, just the offset from the start time. The chart is populated while the user runs a process so I don’t know the min and max before starting to to chart the data.
Ideally I’d like to be able to add the datapoints using a timespan for the X value since that means it wouldn’t matter if they are a second apart or a minute apart (I will have both). Then I’d like the X-axis labels to show hours and minutes in 00:00 format.
Is this possible?
Originally I just added the data points using the absolute time offset in seconds or minutes but then the labels don’t make much sense.
I could continue to use seconds as the x-axis if I had a good way to format the labels but I’m still not sure how best to add custom markers to the x-axis, especially if the user zooms in with the zoom tool. With live data coming in would I have to clear the custom label collection and remake it with each data point? It seems like I wouldn’t be able to use any of the autoscale features if I’m adding custom labels to the axis.
Thanks in advance for any guidance you can provide.
Imported from legacy forums. Posted by Steve (had 3240 views)User (Old forums)MemberOctober 22, 2008 at 10:39 amPost count: 23064
It should be possible to do what you want. You can make the X axis use a time span instead of an absolute date, and you can use the ValueFormatting.Format property so it uses time instead of date for labels. Now, for the DataZoomTool to work on a minutes or hours time span, you also need to set it up properly, because the default value makes it zoom down to only one day.
private void initializeChart()
StandardAxis.PrimaryY ).ScaleMode = AxisScaleMode.Numeric;
//setup the X axis
chart.Axis( StandardAxis.PrimaryX ).ScaleMode = AxisScaleMode.DateTime;
StandardAxis.PrimaryX ).StaggerTexts = true;
StandardAxis.PrimaryX ).StaggerLevels = 3;
StandardAxis.PrimaryX ).ValueFormatting.Format = ValueFormat.Time;
StandardAxis.PrimaryX ).DateTimeScale.MajorTickMode = MajorTickModeDateTime.CustomStep;
//set the time span to 1 hour, but it could be minutes or seconds
DateTime span = new DateTime( 1, 1, 1, 1, 0, 0 );
StandardAxis.PrimaryX ).DateTimeScale.CustomStep = new TimeSpan( span.Ticks );
//setup the zoom to use the same time span as the axis
DataZoomTool zoom = new DataZoomTool();
float minHorzPageSize = Convert.ToSingle( span.ToOADate() );
zoom.MinHorzPageSize = minHorzPageSize;
chartControl1.InteractivityOperations.Add( zoom );
//use the date values for the X axis.
line.UseXValues = true;
//feed the data to the chart
line.AddXY( 40, new DateTime( 2008, 1, 1, 5, 30, 20 ).ToOADate() );
new DateTime( 2008, 1, 1, 7, 50, 20 ).ToOADate() );
new DateTime( 2008, 1, 1, 9, 35, 20 ).ToOADate() ); ;
new DateTime( 2008, 1, 1, 12, 15, 20 ).ToOADate() );
new DateTime( 2008, 1, 1, 17, 25, 20 ).ToOADate() );
new DateTime( 2008, 1, 1, 20, 17, 20 ).ToOADate() );
Imported from legacy forums. Posted by André (had 3062 views)
- You must be logged in to reply to this topic.