Page 1 of 1

How to set scrollbar min,max to teechart bottom axis min max

Posted: Mon May 06, 2013 6:11 am
by 16063571
Hi,


I am binding a collection of data from csv file to teechart.
I am showing a scrollbar for teechart data, when it scrolls the data in teechart will get moved.
But I am not able to set correct teechart bottom axis min max values to scrollbar minimum and maximum values.
Also what value can I set the scrollbar value initially on teechart data.

Please suggest to set exact minimum and maximum values for scrollbar from teechart bottom axis.

I have given my code below which works fine showing scrollbar and able to scroll the data.
Scrollbar showing the correct maximum value but minimum value is not equal to teechart bottom axis minvalue.
  • <---Xaml code ---->

    <Grid>
    <Stackpanel>
    <tChart:TChart x:Name="_TChart" ></tChart:TChart>
    <ScrollBar Style="{StaticResource ScrollBarStyle}" Orientation="Horizontal" Height="15" x:Name="PART_HScrollBar"></ScrollBar>
    </Stackpanel>
    </Grid>


    <----- C# code ------>

    double AxisMax = 100;
    double AxisMin = 0;
    double value;


    InitializeChart()
    {
    MapData();
    // Set the Horizondal axis Span
    double minTimeSpan = DateTime.FromOADate(maximumSeriesValue).AddSeconds(GetDisplaySpanInSeconds(TimeSpanType.Minitues) * -1 * timeSpan).ToOADate();
    double maxTimeSpan = DateTime.FromOADate(maximumSeriesValue).AddSeconds(GetDisplaySpanInSeconds(TimeSpanType.Minitues) * 1 * timeSpan).ToOADate();
    tchart.Axes.Bottom.SetMinMax(minTimeSpan, maxTimeSpan);

    hscrollBar.Minimum = tchart.Axes.Bottom.Minimum;
    hscrollBar.Maximum = tchart.Axes.Bottom.Maximum;
    value = tchart.Axes.Bottom.Minimum + ((tchart.Axes.Bottom.Maximum - tchart.Axes.Bottom.Minimum) / 2);
    //hscrollBar.Value = value;

    AxisMin = hscrollBar.Minimum;
    AxisMax = hscrollBar.Maximum;
    }

    private void hscrollBar_Scroll(object sender, ScrollEventArgs e)
    {
    if (hscrollBar.Value < value)
    tchart.Axes.Bottom.SetMinMax(AxisMin - (value - hscrollBar.Value), AxisMax - (value - hscrollBar.Value));
    else
    tchart.Axes.Bottom.SetMinMax(AxisMin + (hscrollBar.Value - value), AxisMax + (hscrollBar.Value - value));
    tchart.Invalidate();
    }

Please suggest me on this.

Re: How to set scrollbar min,max to teechart bottom axis min max

Posted: Mon May 06, 2013 9:38 am
by 10050769
Hello gilbert,

I have made a simple code that allow axis bottom scrolling when it have datetime values:

Xaml code:

Code: Select all

    <Grid Width="692.537" Margin="0,0,0,0">
        <WPF:TChart Height="451.865" Width="685" x:Name="tChart1" />
        <ScrollBar  Orientation="Horizontal"  VerticalAlignment="Bottom" Height="15" x:Name="hscrollBar"/>
</Grid>
C# code:

Code: Select all

  public MainWindow()
        {
            InitializeComponent();
            InitializeChart();
        }
        double AxisMax = 100;
        double AxisMin = 0;
        double value;
        DateTime dt;
        Random rnd; 
        private void InitializeChart()
        {
            Steema.TeeChart.WPF.Styles.Line line1 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
            dt = DateTime.Today;
            tChart1.Aspect.View3D = false; 
            rnd = new Random();
            line1.XValues.DateTime = true; 
            for (int i = 0; i < 100; i++)
            {
                line1.Add(dt, rnd.Next(100));
                dt = dt.AddDays(1); 
            }
         
            tChart1.AfterDraw += tChart1_AfterDraw;
            hscrollBar.Scroll +=hscrollBar_Scroll;
           
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
        {
            tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues[0], tChart1[0].XValues[50]);
            hscrollBar.Minimum = 0;
            hscrollBar.Maximum = 100; 
            value = tChart1.Axes.Bottom.Minimum + ((tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / 2);
           
            AxisMin = hscrollBar.Minimum;
            AxisMax = hscrollBar.Maximum;
        }
        private void hscrollBar_Scroll(object sender, ScrollEventArgs e)
        {
            double tmp = 0.01 * ((int)hscrollBar.Value) * (tChart1[0].XValues.Maximum - tChart1[0].XValues.Minimum);
            tChart1[0].GetHorizAxis.SetMinMax(tChart1[0].XValues.Maximum + tmp, tChart1[0].XValues.Minimum + tmp);

            tChart1.Invalidate();
        }
Could you please, tell us if previous code help you to achieve as you want?

I hope will helps.

Thanks,