我使用TeeChart和直方图系列来显示数据。我想根据值分别给箱子上色,但我只找到了给每个箱子不同上色的选项。我希望显示相同值的箱子具有相同的颜色。这在TeeChart上可行吗?
是的,这是可能的。您可以在填充系列时使用适当的Add方法覆盖或使用BeforeDrawPoint事件来提供颜色值,如下所示:
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Histogram histogram1 = new Histogram(tChart1.Chart);
histogram1.LinePen.Visible = false;
histogram1.LinesPen.Visible = false;
for (int i = 0; i < 20; i++)
{
histogram1.Add(i);
}
histogram1.BeforeDrawPoint += histogram1_BeforeDrawPoint;
}
void histogram1_BeforeDrawPoint(Series series, BeforeDrawPointEventArgs e)
{
series.Colors[e.ValueIndex] = (series.YValues[e.ValueIndex] > 10) ? Color.Red : Color.Blue;
}