Zooming Candle Chart
Posted: Wed Feb 04, 2015 11:22 am
While Zooming Candle Chart only candle height and space between candle increases. I also want that candle width must be increase automatically in same proportion.
Steema Software - Customer Support Forums
http://teechart.com/support/
Code: Select all
Candle series = new Candle();
double widthRatio;
int origCandleWidth;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Series.Add(series);
series.FillSampleValues();
tChart1.Zoomed += tChart1_Zoomed;
tChart1.UndoneZoom += tChart1_UndoneZoom;
tChart1.BeforeDrawSeries += tChart1_BeforeDrawSeries;
tChart1.Draw();
origCandleWidth = series.CandleWidth;
widthRatio = (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / origCandleWidth;
}
bool zoomed = false;
void tChart1_UndoneZoom(object sender, EventArgs e)
{
zoomed = true;
}
void tChart1_Zoomed(object sender, EventArgs e)
{
zoomed = true;
}
void tChart1_BeforeDrawSeries(object sender, Graphics3D g)
{
if(zoomed)
{
double range = tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum;
double tmpRatio = range / origCandleWidth;
if (widthRatio > 0 && widthRatio != tmpRatio)
{
series.CandleWidth = Utils.Round((widthRatio / tmpRatio) * origCandleWidth);
}
else
{
series.CandleWidth = origCandleWidth;
}
}
zoomed = false;
}
If you use the Control's size than the Candle width will not change when you zoom the Chart, which was the original request.Quant wrote:We tried the following code, it worked for us, but can you please include TeeChart Control's Size to calculate candle width?