我正在使用Teechart制作Xamarin表格。我希望能够在图表缩放时调整图表的蜡烛大小,这样它们之间的间距就不大了。 .Zoomed事件有一个问题没有触发,但Steema团队在我的报告后很快修复它。现在还有另一个问题 -
当我使用下面的代码时,我收到异常 - tChart1.Axes.Bottom.Maximum
并且tChart1.Axes.Bottom.Minimum
没有为蜡烛返回正确的值。
public class App : Application
{
public double tChartMax;
public double tChartMin;
public Steema.TeeChart.Chart tChart1;
public Steema.TeeChart.Styles.Candle tSeries;
double widthRatio;
int origCandleWidth;
public App ()
{
var tChart1 = new Steema.TeeChart.Chart ();
var tSeries = new Steema.TeeChart.Styles.Candle ();
tSeries.FillSampleValues (30);
tChart1.Series.Add (tSeries);
tChart1.Aspect.View3D = false;
ChartView chartView = new ChartView {
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
WidthRequest = 400,
HeightRequest = 500
};
tChart1.UndoneZoom += (object sender, EventArgs e) => {
tSeries.Color = Color.Black;
//double range = tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum;
};
tChart1.Zoomed += (object sender, EventArgs e) => {
tSeries.Color = Color.Pink;
tChartMax = tChart1.Axes.Bottom.Maximum;
tChartMin = tChart1.Axes.Bottom.Minimum;
double range = tChartMax - tChartMin;
};
tChart1.Zoomed += tChart1_Zoomed;
tChart1.UndoneZoom += tChart1_UndoneZoom;
tChart1.BeforeDrawSeries += tChart1_BeforeDrawSeries;
origCandleWidth = tSeries.CandleWidth;
widthRatio = (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / origCandleWidth;
chartView.Model = tChart1;
MainPage = new ContentPage {
Content = new StackLayout {
Children = {
chartView,
}
},
};
}
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)
{
tSeries.CandleWidth = Utils.Round((widthRatio / tmpRatio) * origCandleWidth);
}
else
{
tSeries.CandleWidth = origCandleWidth;
}
}
zoomed = false;
}
}
答案 0 :(得分:0)
这个问题的答案包含在Narcis Calvet的评论中:
我能想到的最简单的选择是设置tChart1.Touch.Style = TouchStyle.FullChart;。更多信息可以在http://www.teechart.net/docs/teechart/net/libpcl/html/SteemaTeeChartTouchStyle.htm
找到