Zoom in to specific series (line graph)

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
LibDundas
Newbie
Newbie
Posts: 55
Joined: Fri Mar 20, 2009 12:00 am

Zoom in to specific series (line graph)

Post by LibDundas » Thu Mar 26, 2009 9:23 pm

Is it possible to zoom in to a specific series line graph?

Or how can I calculate the outside dimensions of a particular series so I can use the tChart.Zoom.ZoomRect() method?

Thanks,
Kevin

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Fri Mar 27, 2009 9:04 am

Hi Kevin,

I think that the easiest way to do this would be using custom axes. Note that custom axes don't zoom by default. So, a possibility, would be to assign your "non zooming series" to custom axes and the other series will be the only one zoomed.

Here there is an example, that uses a numericUpDown control to choose the series to zoom:

Code: Select all

        Steema.TeeChart.Axis CustomVert, CustomHoriz;

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            chartController1.Chart = tChart1;

            for (int i = 0; i < 4; i++)
            {
                new Line(tChart1.Chart);
                tChart1[i].FillSampleValues(100);
            }

            numericUpDown1.Maximum = 3;


            CustomVert = new Steema.TeeChart.Axis(false, false, tChart1.Chart);
            CustomHoriz = new Steema.TeeChart.Axis(true, false, tChart1.Chart);
            tChart1.Axes.Custom.Add(CustomVert);
            tChart1.Axes.Custom.Add(CustomHoriz); 

            tChart1.Panel.MarginLeft = 7;
            tChart1.Panel.MarginBottom = 10;

            tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
        }

        void tChart1_Zoomed(object sender, EventArgs e)
        {
            for (int i = 0; i < tChart1.Series.Count; i++)
            {
                if (i == numericUpDown1.Value)
                {
                    tChart1[i].CustomVertAxis = tChart1.Axes.Left;
                    tChart1[i].CustomHorizAxis = tChart1.Axes.Bottom;
                }
                else
                {
                    tChart1[i].CustomVertAxis = CustomVert;
                    tChart1[i].CustomHorizAxis = CustomHoriz;
                }
            }
        }
Of course, here you should hide some axes labels or draw left axis labels more to the left, and the bottom axis labels more to the bottom. Or something similar to avoid labels superposition.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

LibDundas
Newbie
Newbie
Posts: 55
Joined: Fri Mar 20, 2009 12:00 am

Post by LibDundas » Fri Mar 27, 2009 2:30 pm

Hi Yeray, thanks for the prompt reply. I ended up going with my second option because I was reading the "Articles" on this website (http://www.teechart.net/reference/articles/index.php)

There was info about zooming and scrolling so I went wtih it and came up with this:

Code: Select all

// basically I determine the number of series that exist
int valueForTopLayerSeries = tChart.Series.Count - 1;

double minX = tChart.Series[valueForTopLayer].MinXValue();
double maxX = tChart.Series[valueForTopLayer].MaxXValue();
double minY = tChart.Series[valueForTopLayer].MinYValue();
double maxY = tChart.Series[valueForTopLayer].MaxYValue() * 1.1;    // add 10% so the top mark doesn't get cut off

int x = tChart.Series[valueForTopLayer].CalcXPosValue(minX);
int y = tChart.Series[valueForTopLayer].CalcYPosValue(maxY);

int width = tChart.Series[valueForTopLayer].CalcXPosValue(maxX) - x;
int height = tChart.Series[valueForTopLayer].CalcYPosValue(minY) - y;

Rectangle rect = new Rectangle(x, y, width, height);

tChart.Zoom.ZoomRect(rect);

Post Reply