控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

使用Aspose Cells电子数据表格控件创建图表

作者:ComponentCN 出处:ComponentCN 2014年05月15日 阅读:

使用Aspose Cells电子数据表格控件创建图表,Aspose Cells是一款功能强大的,在没安装Excel的情况下可对Excel文件进行读取,修改,导出的NET和Java控件产品,控件提供了Aspose.Cells.Charts类用于创建图表。
支持的图表类型如下:

  • Column 
  • ColumnStacked 
  • Column100PercentStacked 
  • Column3DClustered 
  • Column3DStacked 
  • Column3D100PercentStacked 
  • Column3D 
  • Bar 
  • BarStacked 
  • Bar100PercentStacked
  • Bar3DClustered 
  • Bar3DStacked 
  • Bar3D100PercentStacked 
  • Line
  • LineStacked 
  • Line100PercentStacked 
  • LineWithDataMarkers 
  • LineStackedWithDataMarkers
  • Line100PercentStackedWithDataMarkers 
  • Line3D 
  • Pie 
  • Pie3D 
  • PiePie 
  • PieExploded 
  • Pie3DExploded 
  • PieBar 
  • Scatter 
  • ScatterConnectedByCurvesWithDataMarker 
  • ScatterConnectedByCurvesWithoutDataMarker 
  • ScatterConnectedByLinesWithDataMarker 
  • ScatterConnectedByLinesWithoutDataMarker 
  • Area 
  • AreaStacked 
  • Area100PercentStacked 
  • Area3D 
  • Area3DStacked 
  • Area3D100PercentStacked 
  • Doughnut  Represents Doughnut Chart
  • DoughnutExploded 
  • Radar 
  • RadarWithDataMarkers 
  • RadarFilled 
  • Surface3D 
  • SurfaceWireframe3D 
  • SurfaceContour 
  • SurfaceContourWireframe 
  • Bubble 
  • Bubble3D 
  • Cylinder 
  • CylinderStacked 
  • Cylinder100PercentStacked 
  • CylindericalBar 
  • CylindericalBarStacked 
  • CylindericalBar100PercentStacked 
  • CylindericalColumn3D 
  • Cone 
  • ConeStacked 
  • Cone100PercentStacked 
  • ConicalBar 
  • ConicalBarStacked 
  • ConicalBar100PercentStacked 
  • ConicalColumn3D 
  • Pyramid 
  • PyramidStacked 
  • Pyramid100PercentStacked 
  • PyramidBar 
  • PyramidBarStacked 
  • PyramidBar100PercentStacked
  • PyramidColumn3D

大致步奏如下:
1. 首先使用Cell对象的PutValue为单元格添加值
2. 通过Charts对象的Add方法添加图表
3. 指定图表的类型,通过 ChartType枚举。
4. 通过索引在Charts集合中存取Chart对象。
5. 使用chart对象的属性或者方法进行图表的相关设置,如 SeriesCollection对象用于指定数据源
当添加数据源时,可以指定单元格的范围如:"A1:C3"或者指定一些非临近的单元格,如:"A1, A3, A5",或者直接指定一序列值,如:"1,2,3"。
注意当指定数据源是单元格范围时,要遵循左上到右下的原则,如"A1:C3" 是有效的,"C3:A1"是无效的。

下面我们举例说明:

[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();

//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();

//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

//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(4);

//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(20);

//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);

//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 15, 5);

//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

//Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

//Saving the Excel file
workbook.Save("C:\\book1.xls");
 
[VB.NET]

'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()

'Adding a new worksheet to the Excel object
Dim sheetIndex As Integer = workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)

'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(4)

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

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

'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 15, 5)

'Accessing the instance of the newly added chart
Dim chart As Aspose.Cells.Charts.Chart = worksheet.Charts(chartIndex)

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

'Saving the Excel file
workbook.Save("C:\book1.xls")
 
下面的事例,我们简单的修改图表类型用于创建线性图:


 

[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();

//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();

//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

//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(4);

//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(20);

//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);

//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line, 5, 0, 15, 5);

//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

//Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

//Saving the Excel file
workbook.Save("C:\\book1.xls");
 
VB.NET
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()

'Adding a new worksheet to the Excel object
Dim sheetIndex As Integer = workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(sheetIndex)

'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(4)

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

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

'Adding a chart to the worksheet
Dim chartIndex As Integer = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line, 5, 0, 15, 5)

'Accessing the instance of the newly added chart
Dim chart As Aspose.Cells.Charts.Chart = worksheet.Charts(chartIndex)

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

'Saving the Excel file
workbook.Save("C:\book1.xls")
 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统