TeeChart for .NET支持对图表中的数据点进行垂直或者水平放大与滚动,当图表中数据点比较多时,需要设置一次滚动或者放大的级数,也就是一次滚动或者放大时所涉及的数据点的数量,举个实例,在蜡烛图中有30到180个蜡烛,客户需要每次放大时只放大10个蜡烛,也就是10个数据点,那么如何使用
TeeChart for .NET实现这种功能呢,具体可以参考下面的部分代码,对于其他类型的图表实现方法也是类似:
Candle candle1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
candle1 = new Candle(tChart1.Chart);
candle1.FillSampleValues(100);
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
tChart1.Zoomed += TChart1_Zoomed;
tChart1.Scroll += TChart1_Scroll;
}
private void TChart1_Scroll(object sender, EventArgs e)
{
double first = candle1.XValues.First;
if(tChart1.Axes.Bottom.Maximum < first)
{
tChart1.Axes.Bottom.Maximum = first;
}
}
private void TChart1_Zoomed(object sender, EventArgs e)
{
List<double> xvalues = candle1.XValues.Value.ToList();
double first = xvalues.First(x => x >= tChart1.Axes.Bottom.Minimum);
int firstIndex = xvalues.IndexOf(first);
double last = xvalues[firstIndex + 9];
tChart1.Axes.Bottom.Maximum = last;
}