我正在使用 SpreadsheetGear 2010 来绘制柱形图,并希望循环遍历所有数据点,将负数着色为红色......但是当我循环遍历时,我看不到获得该点“值”的方法。
以下(将数据标签字符串解释为双精度值)大部分时间都有效:
for (int i = 0; i < chart.SeriesCollection.Count; i++)
{
positiveColor = Color.FromArgb(79, 129, 189); // blue
negativeColor = Color.FromArgb(192, 80, 77); // red
chart.SeriesCollection[i].HasDataLabels = true;
for (int j = 0; j < chart.SeriesCollection[i].Points.Count; j++)
{
double pointValue;
// If the point is -0.004 but the number format is "0.00",
// label will be "0.00"
string label = chart.SeriesCollection[i].Points[j].DataLabel.Text;
chart.SeriesCollection[i].Points[j].Format.Fill.ForeColor.RGB =
(System.Double.TryParse(label, out pointValue) && pointValue >= 0)
? positiveColor
: negativeColor;
}
}
...但是,如果该值略微为负,则数据标签仅显示为零,因此 pointValue >= 0 并且我将该点解释为正。这会导致恼人的小蓝点从我的 X 轴上垂下来。
SpreadsheetGear.Charts.IPoint
似乎没有任何有用的属性来检索用于绘制点的值。
chart.SeriesCollection[i].Values
看起来很有希望,但返回一个object
字符串解释为“=Data!$B$25:$B$44”。我似乎无法将其转换为任何有用的东西,也找不到任何相关的 SpreadsheetGear 文档。
知道如何获得用于绘制点的值吗?