Home Forums WinForms controls Xceed Chart for WinForms How best to use a timespan as the X value

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19012 |

    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)
    Member
    Post 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.

    e.g.:

    private void initializeChart()

    {

        chart.Axis(

    StandardAxis.PrimaryY ).ScaleMode = AxisScaleMode.Numeric;

     

        //setup the X axis

        chart.Axis( StandardAxis.PrimaryX ).ScaleMode = AxisScaleMode.DateTime;

        chart.Axis(

    StandardAxis.PrimaryX ).StaggerTexts = true;

        chart.Axis(

    StandardAxis.PrimaryX ).StaggerLevels = 3;

        chart.Axis(

    StandardAxis.PrimaryX ).ValueFormatting.Format = ValueFormat.Time;

        chart.Axis(

    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 );

        chart.Axis(

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

        line.AddXY( 45,

    new DateTime( 2008, 1, 1, 7, 50, 20 ).ToOADate() );

        line.AddXY( 50,

    new DateTime( 2008, 1, 1, 9, 35, 20 ).ToOADate() ); ;

        line.AddXY( 30,

    new DateTime( 2008, 1, 1, 12, 15, 20 ).ToOADate() );

        line.AddXY( 25,

    new DateTime( 2008, 1, 1, 17, 25, 20 ).ToOADate() );

        line.AddXY( 35,

    new DateTime( 2008, 1, 1, 20, 17, 20 ).ToOADate() );

    }

     

    Imported from legacy forums. Posted by André (had 3062 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.