Greetings.
I am trying to implement a scrollbar to use with Teechart.
How does one keep track of "how zoomed in" a chart is ...
you can zoom a chart in by a given percent(.ZoomPercent Method)
But there is no read value that I can see ...
Please point me in the right direction ... do I use a property of the axis ? which I would assume I'd store intial value and compare to the axis value after a zoom and ' then 'do the math'
Is there a property that will tell me the size of the chart area unzoomed and another that will tell me the size of the 'zoomed window' with which I can calculate a percentage zoom ?
Or is there a better way ???
TeeCHart Newbie Q1 of 1022 Zooming and Scrolling
TeeCHart Newbie Q1 of 1022 Zooming and Scrolling
--------------------
Cheers Phil.
Cheers Phil.
Re: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling
Hello Snarkle,
I have proposed a simple solution that calculates the ZoomPercent of Chart Zoom, using values of Axes and Zoomed and Unzoomed Events. Could you please check next code works as you want?
I hope will helps.
Thanks,
I have proposed a simple solution that calculates the ZoomPercent of Chart Zoom, using values of Axes and Zoomed and Unzoomed Events. Could you please check next code works as you want?
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private double XRange0;
private double YRange0;
private double GetAxisRange(Steema.TeeChart.Axis axis)
{
return axis.Maximum - axis.Minimum;
}
private void DisplayZoomPercentage(double x, double y)
{
tChart1.Header.Text = "Horizontal zoom: " + x.ToString("0.##") + ",Vertical zoom: " + y.ToString("0.##");
}
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new
Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.Draw();
XRange0 = GetAxisRange(tChart1.Axes.Bottom);
YRange0 = GetAxisRange(tChart1.Axes.Left);
tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
}
void tChart1_UndoneZoom(object sender, EventArgs e)
{
DisplayZoomPercentage(0, 0);
}
void tChart1_Zoomed(object sender, EventArgs e)
{
double XRange1 = GetAxisRange(tChart1.Axes.Bottom);
double YRange1 = GetAxisRange(tChart1.Axes.Left);
double XZoom = 100 - ((XRange1 / XRange0) * 100);
double YZoom = 100 - ((YRange1 / YRange0) * 100);
DisplayZoomPercentage(XZoom, YZoom);
}
Thanks,
Best Regards,
Sandra Pazos / 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: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling
Thanks Sandra ... that code snippet has pointed me in the right direction ...
However I have another question regarding the code snippet.
Currently the only way I can find to get the intial value for XRange0 is from the event
The first time this event fires I get a zero, soon after the event fires again and I get the value that I require and I can store.
I am nervous about this method .. I am not sure this approach is even approaching being consistent.
Everywhere else I put this code the result always came back as zero
Is there a property that can always tell me what the axis.maximum and axis.minimum are regardless of how zoomed it is ???
i.e. .. as soon as I zoom the chart XRange0 will be overwritten with a new value.
I tried calling XRange0 = GetAxisRange(StockChart.Axes.Bottom); Directly after populating a candle series and adding it to a chart but again I got a 0.
OH and another quick question how can I scroll to an exact position ... there is a scroll method(Steema.TeeChart.Axis.Scroll) that takes an offset and scrolls from the current position in the direction of the offset but what if I want to scroll to predefined positions in the chart 1.e. the Starting point, 50% of the chart 75% of the chart etc ... what method can I use.
Cheers Phil.
However I have another question regarding the code snippet.
Currently the only way I can find to get the intial value for XRange0 is from the event
Code: Select all
private bool doneOnce = false;
private double XRangeMax = 0;
private void StockChart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
XRange0 = GetAxisRange(StockChart.Axes.Bottom);
if (XRange0 != 0 && doneOnce == false)
{
/// I need the second value from this event.
XRangeMax = XRange0;
doneOnce = true;
}
}
I am nervous about this method .. I am not sure this approach is even approaching being consistent.
Everywhere else I put this code the result always came back as zero
Is there a property that can always tell me what the axis.maximum and axis.minimum are regardless of how zoomed it is ???
i.e. .. as soon as I zoom the chart XRange0 will be overwritten with a new value.
I tried calling XRange0 = GetAxisRange(StockChart.Axes.Bottom); Directly after populating a candle series and adding it to a chart but again I got a 0.
OH and another quick question how can I scroll to an exact position ... there is a scroll method(Steema.TeeChart.Axis.Scroll) that takes an offset and scrolls from the current position in the direction of the offset but what if I want to scroll to predefined positions in the chart 1.e. the Starting point, 50% of the chart 75% of the chart etc ... what method can I use.
Cheers Phil.
Re: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling
Hello Phil,
Could you please check if our code works fine for you?
I hope will helps.
Thanks,
Method tChart1.Draw() paints the complete Axis (Ticks, Grid, Labels, Title) using the Axis.ParentChart.Canvas. Normally you do not need to call the Draw method directly, but in it case is necessary, because until chart isn't painted, properties that you use for get values, can not have been calculated and you don't have correctly values.Currently the only way I can find to get the intial value for XRange0 is from the event
private bool doneOnce = false;
private double XRangeMax = 0;
private void StockChart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
XRange0 = GetAxisRange(StockChart.Axes.Bottom);
if (XRange0 != 0 && doneOnce == false)
{
/// I need the second value from this event.
XRangeMax = XRange0;
doneOnce = true;
}
}
The first time this event fires I get a zero, soon after the event fires again and I get the value that I require and I can store.
I am nervous about this method. I am not sure this approach is even approaching being consistent.
Everywhere else I put this code the result always came back as zero
Is there a property that can always tell me what the axis.maximum and axis.minimum are regardless of how zoomed it is ???
i.e. .. as soon as I zoom the chart XRange0 will be overwritten with a new value.
I tried calling XRange0 = GetAxisRange(StockChart.Axes.Bottom); Directly after populating a candle series and adding it to a chart but again I got a 0.
Could you please check if our code works fine for you?
I recommend that use SetMinMax() method, for calculate scroll with your values. You can find examples about it in TeeChart .net Demo concretely in All Features\Welcome !\Miscellaneous\Zoom and Scroll.OH and another quick question how can I scroll to an exact position ... there is a scroll method(Steema.TeeChart.Axis.Scroll) that takes an offset and scrolls from the current position in the direction of the offset but what if I want to scroll to predefined positions in the chart 1.e. the Starting point, 50% of the chart 75% of the chart etc ... what method can I use.
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 |
Instructions - How to post in this forum |