How to fit all the lines into a chart
Re: How to fit all the lines into a chart
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.
I place TChart like,
Form<-Panel<-TChart.
But then with fixed tool window, if I Pan it is still breaking.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
You have two options here: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.
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 |
Re: How to fit all the lines into a chart
//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.
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.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
Yes, this is what this code does:Raavi wrote: Is it possible to achieve zoom-in and zoom-out and keep aspect ratio when re-sizing window.
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);
}
}
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 |
Re: How to fit all the lines into a chart
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?
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?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
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.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?
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 |
Re: How to fit all the lines into a chart
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.
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
-
- re-size
- 3.png (30.44 KiB) Viewed 20108 times
-
- //m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();
- 2.png (32.9 KiB) Viewed 20098 times
-
- lines out of chart.
- 1.png (27.55 KiB) Viewed 20103 times
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
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.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.
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 |
Re: How to fit all the lines into a chart
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.
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 (18.48 KiB) Viewed 20091 times
-
- OnCreate.png (19.45 KiB) Viewed 20089 times
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
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?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.
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 |
Re: How to fit all the lines into a chart
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,
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
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
If I comment out these two lines: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,
Code: Select all
//m_Line.IsoHorizAxes = true;
//m_Chart.BeforeDrawSeries += (sender, d) => m_Chart.Chart.Axes.Bottom.AdjustMaxMin();
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 |
Re: How to fit all the lines into a chart
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();
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();
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: How to fit all the lines into a chart
Hello,
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:
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.
The only way to do this is to use IsoHorizAxes instead of IsoVertAxes.Raavi wrote: * My humble question is, Is it possible to bring the polygon into the Chart when the lines are set to
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:
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 |
Re: How to fit all the lines into a chart
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.
I am not an expert in 2D-graphics but I assume that this feature is not available for consumption yet.