Move Subchart with SelectrorTool

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Move Subchart with SelectrorTool

Post by asupriya » Wed Aug 05, 2009 12:27 pm

I have a subchart tool and like to have the selector tool of main chart move the subchart location on the main chart. I am wondering if you have any example code for this purpose.

Thanks,

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Move Subchart with SelectrorTool

Post by Sandra » Thu Aug 06, 2009 9:50 am

Hello asupriya,

I communicate that in this moment is not possible using selector Tool to select SubChart. But, you can select manually SubChart as next example:

Code: Select all

         public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.FastLine fastline1;
        Steema.TeeChart.Styles.Line line;
        Steema.TeeChart.Tools.Selector selector1;
        Steema.TeeChart.Tools.SubChartTool subtool;
        Steema.TeeChart.TChart SubChart1;
        bool dragSubChart;//variable to drag or not drag subChart.

        private void InitializeChart()
        {

            fastline1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            //--------------------Initialize SubChart----------------
            subtool = new Steema.TeeChart.Tools.SubChartTool(tChart1.Chart);
            SubChart1 = subtool.Charts.AddChart("SubChart1");
            SubChart1.Chart.Parent = SubChart1;
            SubChart1.Top = 0;
            SubChart1.Width = tChart1.Width / 4;
            SubChart1.Height = tChart1.Height / 4;
            SubChart1.Header.Visible = false; 
            SubChart1.Aspect.View3D = false;
            SubChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
            SubChart1.Panel.MarginLeft = 1;
            SubChart1.Panel.MarginRight = 1;
            SubChart1.Panel.MarginTop = 1;
            SubChart1.Panel.MarginBottom = 1;
   
            SubChart1.Axes.Bottom.Labels.Visible = true;
            SubChart1.Axes.Left.Labels.Visible = false;
            line= new Steema.TeeChart.Styles.Line(SubChart1.Chart);
            line.FillSampleValues(200);
            line.Color = Color.Red;
            //------------------Initialize elements of Chart----------------
            fastline1.FillSampleValues(500);
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            selector1 = new Steema.TeeChart.Tools.Selector(tChart1.Chart);
            selector1.AllowResizeChart = true;
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
        }
        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
                dragSubChart = false;
                SubChart1.Panel.Pen.Visible = false;  
        }
        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {        
                Rectangle rect = SubChart1.Chart.ChartRect;
                if (rect.Contains(e.X, e.Y))
                {
                    dragSubChart = true;
                    SubChart1.Panel.Pen.Visible = true;
                    SubChart1.Panel.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
                    SubChart1.Panel.Pen.Color = Color.Red;
                }

        }

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            this.Text = e.Location.ToString();

            if (dragSubChart)
            {
                SubChart1.Top = e.Y;
                SubChart1.Left = e.X;
            }

        }

        void selector1_Selected(object sender, EventArgs e)
        {
            Steema.TeeChart.ChartClickedPart selectorPart = new Steema.TeeChart.ChartClickedPart();
            selectorPart = selector1.Part;
            if (selector1 != null)
            {
                switch (selectorPart.Part)
                {
                    case Steema.TeeChart.ChartClickedPartStyle.Series:
                        tChart1.Legend.Visible = false;
                        break;

                    case Steema.TeeChart.ChartClickedPartStyle.Axis:
                        tChart1.Legend.Visible = true;
                        break;

                }

            }

        }

Please, check that previous code works in your application.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Move Subchart with SelectrorTool

Post by asupriya » Fri Aug 07, 2009 6:15 am

Thanks. It was helpful.

I have two follow up questions:

1. I am creating chart, subcharttool and its subchart at runtime and adding multiple polarBar series to the subchart at runtime. How can i access the polar bar on the subchart at runtime to change its valued as per the main chart's fastline series. The statement

Code: Select all

Dim mySubChart As Steema.TeeChart.Tools.SubChart 
For a = 0 To myActiveChart.Tools.Count - 1
                If TypeOf myActiveChart.Tools(a) Is Steema.TeeChart.Tools.SubChartTool Then
                    mySubChart = CType(myActiveChart.Tools(a), Steema.TeeChart.Tools.SubChartTool).Charts(0)
                    Exit For
                End If
            Next
compiles without error. However, mySubChart doesn't let me access its series. Please help.

2. I have multiple custom Y-axes on the left side of the chart. How can I adjust the location of subchart to automatically be at the beginning of rightmost Y-axis.

Thanks

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Move Subchart with SelectrorTool

Post by Sandra » Fri Aug 07, 2009 10:05 am

Hello asupriya,
I am creating chart, subCharTool and its subchart at runtime and adding multiple polarBar series to the subchart at runtime. How can i access the polar bar on the subchart at runtime to change its valued as per the main chart's fastline series.
I recomen works with runtime, and add SubChart tool in this as explain last example that I put in the post.But if you want to use dessing time you could access to SubChart as next code of example:

Code: Select all

Dim subChart As Steema.TeeChart.Tools.SubChart
    Private Sub InitializeChart()
        subChart = subChartTool1.Charts(0)
        Dim line1 As Steema.TeeChart.Styles.Line = New Steema.TeeChart.Styles.Line(subChart.Chart.Chart)
        Dim bar As Steema.TeeChart.Styles.Bar = New Steema.TeeChart.Styles.Bar(tChart1.Chart)
        '---SubChart---//
        line1.FillSampleValues(10)
        line1.Color = Color.Red
        '---TChart---//
        bar.FillSampleValues
    End Sub
I have multiple custom Y-axes on the left side of the chart. How can I adjust the location of subchart to automatically be at the beginning of rightmost Y-axis.
If you want to change position of SubChart, you only change value of top and left properties of SubChart. Please see next example and check that works fine in your application.

Add this line in InitialitzeChart:

Code: Select all

'---Change Position--- this line is that add.
        AddHandler tChart1.AfterDraw, AddressOf Me.tChart1_AfterDraw
        tChart1.Draw
After Draw Event:

Code: Select all

 void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            Rectangle rect = new Rectangle();
            rect = tChart1.Chart.ChartRect;
            subChart.Top = rect.Top - (int)tChart1.Panel.MarginTop;
            subChart.Left = rect.Width - (int)tChart1.Panel.MarginRight;  
        }
Also, if you prefer not use AfterDraw event you can change values directly in the InitializeChart, for example:

Code: Select all

Dim subChart As Steema.TeeChart.Tools.SubChart

    
    Private Sub InitializeChart()
        subChart = subChartTool1.Charts(0)
        Dim line1 As Steema.TeeChart.Styles.Line = New Steema.TeeChart.Styles.Line(subChart.Chart.Chart)
        Dim bar As Steema.TeeChart.Styles.Bar = New Steema.TeeChart.Styles.Bar(tChart1.Chart)
        '---SubChart---
        line1.FillSampleValues(10)
        line1.Color = Color.Red
        '---TChart---
        bar.FillSampleValues
        '---Change Position--- this line is that add.
        tChart1.Draw
        'You need draw before change position.
        Dim rect As Rectangle = New Rectangle
        rect = tChart1.Chart.ChartRect
        subChart.Top = (rect.Top - CType(tChart1.Panel.MarginTop,Integer))
        subChart.Left = (rect.Width - CType(tChart1.Panel.MarginRight,Integer))
    End Sub
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Re: Move Subchart with SelectrorTool

Post by asupriya » Thu Aug 20, 2009 4:18 am

When I drag subchart, the main chart is being zoomed. How can i prevent it from zooming while subchart is being dragged. Setting TChart1.zoom.allow = false is not helping at runtime.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Move Subchart with SelectrorTool

Post by Sandra » Thu Aug 20, 2009 11:26 am

Hello asupriya,

I have do changes in last code I send. Please check that adding subChart.Chart.Zoom.Allow and TChart1.Zoom.Allow in next events works correctly your application:

MouseUp Event

Code: Select all

 Private Sub tChart1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
        dragSubChart = False
        subChart.Chart.Panel.Pen.Visible = False
        subChart.Chart.Zoom.Allow = True
        TChart1.Zoom.Allow = True
    End Sub

Mouse_MoveEvent:

Code: Select all

Private Sub tChart1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        Me.Text = e.Location.ToString
        If dragSubChart Then
            subChart.Chart.Top = e.Y
            subChart.Chart.Left = e.X
            subChart.Chart.Zoom.Allow = False
            TChart1.Zoom.Allow = False
        End If
    End Sub
If code I made previously not solve your problem. Please you could send us a simple example project that we can reproduce your problem here? You can attach you project directly in the forums post.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply