ChartPointCollection

ChartPointCollection class

表示包含一个系列中所有点的集合。

public class ChartPointCollection

特性

姓名描述
Count { get; }获取图表点的计数。
Item { get; }获取ChartPoint系列中指定索引处的元素。

方法

姓名描述
Clear()删除图表点的所有设置。
GetEnumerator()返回整个枚举数ChartPointCollection.
RemoveAt(int)删除系列索引处的点..

例子

//实例化一个工作簿对象
Workbook workbook = new Workbook();

//获取第一个工作表的引用
Worksheet worksheet = workbook.Worksheets[0];

//向“A1”单元格添加样本值
worksheet.Cells["A1"].PutValue(50);

//向“A2”单元格添加样本值
worksheet.Cells["A2"].PutValue(100);

//向“A3”单元格添加样本值
worksheet.Cells["A3"].PutValue(150);

//向“B1”单元格添加样本值
worksheet.Cells["B1"].PutValue(60);

//向“B2”单元格添加样本值
worksheet.Cells["B2"].PutValue(32);

//向“B3”单元格添加样本值
worksheet.Cells["B3"].PutValue(50);

//向工作表添加图表
int chartIndex = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10);

//访问新添加图表的实例
Chart chart = worksheet.Charts[chartIndex];

//将NSeries(图表数据源)添加到从“A1”单元格到“B3”单元格的图表中
chart.NSeries.Add("A1:B3", true);

//显示数据标签 
chart.NSeries[0].DataLabels.IsValueShown = true;

ChartPointCollection points = chart.NSeries[0].Points;

for (int i = 0; i < points.Count; i++)
{
    //获取数据点
    ChartPoint point = points[i];
    //设置Pir爆炸
    point.Explosion = 15;
    //设置边框颜色
    point.Border.Color = System.Drawing.Color.Red;
}

//保存Excel文件
workbook.Save("book1.xls");

[VB.NET]

'实例化工作簿对象
Dim workbook As Workbook = New Workbook()

'获取第一个工作表的引用
Dim worksheet As Worksheet = workbook.Worksheets(0)

'Adding a sample value to "A1" cell
worksheet.Cells("A1").PutValue(50)

'Adding a sample value to "A2" cell
worksheet.Cells("A2").PutValue(100)

'Adding a sample value to "A3" cell
worksheet.Cells("A3").PutValue(150)

'Adding a sample value to "B1" cell
worksheet.Cells("B1").PutValue(60)

'Adding a sample value to "B2" cell
worksheet.Cells("B2").PutValue(32)

'Adding a sample value to "B3" cell
worksheet.Cells("B3").PutValue(50)

'将图表添加到工作表
Dim chartIndex As Integer = worksheet.Charts.Add(ChartType.PieExploded, 5, 0, 25, 10)

'访问新添加图表的实例
Dim chart As Chart = worksheet.Charts(chartIndex)

'Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", True)

'显示数据标签 
chart.NSeries(0).DataLabels.IsValueShown = True

Dim points As ChartPointCollection = chart.NSeries(0).Points

For i As Integer = 0 To points.Count - 1
    '获取数据点
    Dim point As ChartPoint = points(i)
    '设置 Pir 爆炸
    point.Explosion = 15
    '设置边框颜色
    point.Border.Color = System.Drawing.Color.Red
Next i

'保存 Excel 文件
workbook.Save("book1.xls")

也可以看看