How to fit all the lines into a chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 03, 2014 11:12 am

Yes, that is true. Right now it is fixed tool window but I really anticipate the window will become re-sizable.

I place TChart like,

Form<-Panel<-TChart.

But then with fixed tool window, if I Pan it is still breaking.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Tue Jun 03, 2014 1:30 pm

Raavi wrote:Yes, that is true. Right now it is fixed tool window but I really anticipate the window will become re-sizable.

I place TChart like,

Form<-Panel<-TChart.

But then with fixed tool window, if I Pan it is still breaking.
You have two options here:

Code: Select all

            //m_Chart.Panning.Allow = Steema.TeeChart.ScrollModes.None; //option 1
            m_Chart.ScrollMod += m_Chart_ScrollMod; //option 2
        }

        void m_Chart_ScrollMod(Steema.TeeChart.Axis a, Steema.TeeChart.ScrollModEventArgs e)
        {
          if (a.Equals(m_Chart.Axes.Left))
          {
            e.Max = m_Line.YValues.Maximum;
            e.Min = m_Line.YValues.Minimum;
          }
          else if (a.Equals(m_Chart.Axes.Bottom))
          {
            e.Max = m_Line.XValues.Maximum;
            e.Min = m_Line.XValues.Minimum;
          }
        }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 03, 2014 2:11 pm

//m_Line.IsoHorizAxes = true;

May break the aspect ratio.

==============

1) I need to draw lines on Chart.

2) Maintain aspect ratio, pref HorizAxes.

3) Re-size the Chart, this should also re-size and maintain aspect-ratio of the lines.

Lets not worry about the fixed size window.

Is it possible to achieve zoom-in and zoom-out and keep aspect ratio when re-sizing window.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Wed Jun 04, 2014 8:07 am

Raavi wrote: Is it possible to achieve zoom-in and zoom-out and keep aspect ratio when re-sizing window.
Yes, this is what this code does:

Code: Select all

   public partial class Form1 : Form
    {
        private readonly double[] m_RectangleX = new double[5];
        private readonly double[] m_RectangleY = new double[5];
        private readonly Line m_Line = new Line();
        private double m_Sum = 0.0;

        public Form1()
        {
            InitializeComponent();

            m_Chart.Aspect.View3D = false;
            m_Chart.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            m_Chart.Legend.Visible = false;
            m_Chart.Location = new Point(0, 0);
            m_Chart.Name = "Testing TChart";
            m_Chart.TabIndex = 0;
            m_Chart.Chart.Header.Text = "Testing TChart";
            m_Chart.Series.Clear();
            m_Chart.Tools.Clear();

            Load += (sender, args) => AddSeriesToChart();

            Test.Click += (sender, args) => AddSeriesToChart();


            m_Chart.Panning.Allow = Steema.TeeChart.ScrollModes.None;

        }


        private void AddSeriesToChart()
        {
            m_Sum -= 10.0;

            m_RectangleX[0] = -1500000.0 + m_Sum;
            m_RectangleY[0] = -1000000 + m_Sum;

            m_RectangleX[1] = 2500000.0 + m_Sum;
            m_RectangleY[1] = -1500000.0 + m_Sum;

            m_RectangleX[2] = 3500000.0 + m_Sum;
            m_RectangleY[2] = 1500000.0 + m_Sum;

            m_RectangleX[3] = -4500000.0 + m_Sum;
            m_RectangleY[3] = 1500000.0 + m_Sum;

            m_RectangleX[4] = -1000000.0 + m_Sum;
            m_RectangleY[4] = -1500000.0 + m_Sum;
            
            m_Line.XValues.Count = 5;
            m_Line.XValues.Value = m_RectangleX;
            m_Line.XValues.Modified = true;
            
            m_Line.YValues.Count = 5;
            m_Line.YValues.Value = m_RectangleY;
            m_Line.YValues.Modified = true;
            
            m_Chart.Series.Clear();
            m_Chart.Series.Add(m_Line);

            //m_Chart.Axes.Bottom.Automatic = true;
            //m_Chart.Axes.Bottom.MinimumOffset = 10;
            //m_Chart.Axes.Bottom.MaximumOffset = 10;
            ////m_Chart.Axes.Bottom.Visible = false;
            //m_Chart.Axes.Bottom.Ticks.Length = 0;

            //m_Chart.Axes.Left.Automatic = true;
            //m_Chart.Axes.Left.MinimumOffset = 10;
            //m_Chart.Axes.Left.MaximumOffset = 10;
            ////m_Chart.Axes.Left.Visible = false;
            //m_Chart.Axes.Left.Ticks.Length = 0;

            m_Line.IsoHorizAxes = true;

            if(m_Sum == -10) m_Chart.Draw();

            m_Sum -= 10.0;
            Debug.Write("");
            Debug.Write(m_Chart.Zoom.Zoomed);
        }
    }
The issue here, I think is that IsoHorizAxes is not behaving as you might expect, but it is behaving as designed. What IsoHorizAxes does is to make sure that the "XValue per pixel" ratio is the same as the "YValue per pixel" ratio, which in the case of the two axes produces the visible chart. Instead of IsoHorizAxes = true, try IsoVertAxes = true and you will see the relation reversed to produce a chart which is probably more like what you'd expect to see.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Wed Jun 04, 2014 8:52 am

Thanks very much. Yes, that piece of code is doing what it is suppose to do but my intentions are slightly different.

May be I should construct dynamically a bounding box based on lines and perform zoom-in/zoom-out before drawing.

* Is there any other simple solution to do the same?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Wed Jun 04, 2014 9:07 am

Raavi wrote:Thanks very much. Yes, that piece of code is doing what it is suppose to do but my intentions are slightly different.

May be I should construct dynamically a bounding box based on lines and perform zoom-in/zoom-out before drawing.

* Is there any other simple solution to do the same?
Again, I'm afraid I'm not entirely sure exactly what you're intentions are. If IsoVertAxes/IsoHorizAxes doesn't fulfil you needs with respect to the maintenance of aspect ratio, then I'm not sure what will. Certainly there is no way to maintain the horizontal and vertical aspect ratio simultaneously, as without taking either vertical or horizontal as fixed the calculation for the other cannot be made.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Wed Jun 04, 2014 9:33 am

1.png, shows the drawing of the lines with IsoHoriz=true and m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin(); event fired.

2.png, shows the drawing of the lines with IsoHoriz=true and //m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();

I try to draw all lines that will be bound to the Chart size and keeping the aspect ratio. Try to see something like 2.png in 1.png without re-sizing.

Also attached the re-sized Chart in 3.png.
Attachments
3.png
re-size
3.png (30.44 KiB) Viewed 20111 times
2.png
//m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();
2.png (32.9 KiB) Viewed 20101 times
1.png
lines out of chart.
1.png (27.55 KiB) Viewed 20106 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Wed Jun 04, 2014 4:06 pm

Raavi wrote: I try to draw all lines that will be bound to the Chart size and keeping the aspect ratio. Try to see something like 2.png in 1.png without re-sizing.
It is the aspect ratio that is the problem. The code in this message of mine works as expected, but you say it is not what is required. Using IsoHorizAxes instead of IsoVertAxes works as expected too, as I explained, but this is also not your requirement.

With respect to the aspect ratio, therefore, I am not at all sure that your requirement is realistically achievable, also as I have explained, or if I simply do not fully understand what it is.

To repeat: simultaneous vertical and horizontal aspect ratio adjustment is not possible, the only options with respect to aspect ratio are the two already mentioned.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 10, 2014 9:26 am

Thanks again.

I try to understand the problem now, it seems when using IsoHorizAxes or IsoVertAxes it tries to scale Horizontal or Vertical axis accordingly. This is required for me and it works fine.

Problem on scaling is that it tries to draw lines or points beyond the Chart rectangle.

* My requirement is to draw everything in a Chart rectangle and maintain aspect ration.

OnCreate.png: Drawing beyond the Chart rectangle.

AfterZoomingOut.png: Applying Chart.Zoom.ZoomPercent(100); 3-times.

I aim to implement something like in AfterZoomingOut.png, i.e., no matter what I do all the points or lines stay inside the Chart rectangle.
Attachments
AfterZoomingOut.png
AfterZoomingOut.png (18.48 KiB) Viewed 20094 times
OnCreate.png
OnCreate.png (19.45 KiB) Viewed 20092 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Tue Jun 10, 2014 10:47 am

Raavi wrote:1.png, shows the drawing of the lines with IsoHoriz=true and m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin(); event fired.

2.png, shows the drawing of the lines with IsoHoriz=true and //m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();

I try to draw all lines that will be bound to the Chart size and keeping the aspect ratio. Try to see something like 2.png in 1.png without re-sizing.

Also attached the re-sized Chart in 3.png.
Can you please tell me the code I have to add to your example TestingTeeChartScaling.zip you posted in this message so that I can reproduce these new issues here?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 10, 2014 11:05 am

Here I attach the sample solution.

On running I expect the polygon drawn inside the rectangle, but in this case I have to press '-' key couple of time to bring it back.

Regards,
Attachments
TestingTeeChartScaling.zip
(44.72 KiB) Downloaded 655 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Tue Jun 10, 2014 11:19 am

Raavi wrote:Here I attach the sample solution.

On running I expect the polygon drawn inside the rectangle, but in this case I have to press '-' key couple of time to bring it back.

Regards,
If I comment out these two lines:

Code: Select all

            //m_Line.IsoHorizAxes = true;

            //m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();
then the code works as expected. Do we agree?

With the two lines commented in, we are yet again at the issue of IsoHorizAxes and IsoVertAxes, which we have already discussed several times. As I have already mentioned, IsoHorizAxes is actually rendering as designed, even though you see it as not giving you what you expect.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 10, 2014 11:31 am

Indeed, I get polygon into the chart when I comment those lines.

Also, happy with what IsoHorizAxes or IsoVertAxes does on polygon.

Everything is fine till now.

============================

Problem I have is that I do not want to surprise customers when they design something that is not shown entirely in the Chart without applying ZoomPercent additionally.



* My humble question is, Is it possible to bring the polygon into the Chart when the lines are set to

m_Line.IsoHorizAxes = true;

and chart to

m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to fit all the lines into a chart

Post by Christopher » Tue Jun 10, 2014 12:46 pm

Hello,
Raavi wrote: * My humble question is, Is it possible to bring the polygon into the Chart when the lines are set to
The only way to do this is to use IsoHorizAxes instead of IsoVertAxes.

Maybe having a look at the TeeChart source code will give you a clearer idea of what these properties do ... using ILSpy to open TeeChart.dll, we can see the code in the Axes.Draw method:
AxesDraw.PNG
AxesDraw.PNG (103.54 KiB) Viewed 20081 times
What's happening here is that we take the value range of the two axes, that is, the difference between the maximum and minimum. Then we take the pixel range of the two axes, that is, the difference between the pixel position of the start of the axis and its end. From this we have two ratios, the pixels-per-value of the vertical axis (num5) and the pixels-per-values of the horizontal axis (num6). So, if IsoHorizAxes is set to true, a calculation is made to make the horizontal axis pixels-per-value ratio the same as the vertical axis. In your example, as the pixels-per-value ratio of the vertical axis is bigger than that of the horizontal axis, this means that when IsoHorizAxes is set to true the horizontal axis is made bigger (more pixels per value). That is why you are getting the effect you see, and that is why the only way to get the polygon entirely visible with the vertical and horizontal axis values you have is to set IsoVertAxes to true.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Raavi
Newbie
Newbie
Posts: 36
Joined: Tue Apr 01, 2014 12:00 am

Re: How to fit all the lines into a chart

Post by Raavi » Tue Jun 10, 2014 2:29 pm

Slowly taking that code into my veins but I see it does not take Chart bounds into account.

I am not an expert in 2D-graphics but I assume that this feature is not available for consumption yet.

Post Reply