Tab 1
此演示向您展示如何在 PowerPoint 文档中创建图表。
Data
e-iceblue
Option
e-iceblue
downloads
如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。
如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。
Tab 2
package ppt;import com.spire.data.table.DataColumn;import com.spire.data.table.DataRow;import com.spire.data.table.DataTable;import com.spire.pdf.tables.table.DataTypes;import com.spire.presentation.FileFormat;import com.spire.presentation.Presentation;import com.spire.presentation.charts.ChartType;import com.spire.presentation.charts.IChart;import java.awt.geom.Rectangle2D;public class ChartDemo{public void chartDemoPpt(String resultFilePath,ChartType chartType) throws Exception{Presentation presentation = new Presentation();Rectangle2D rect1 = new Rectangle2D.Double(90,100,550,320);IChart chart = presentation.getSlides().get(0).getShapes().appendChart(chartType,rect1,false);//chart title chart.getChartTitle().getTextProperties().setText("Chart");chart.getChartTitle().getTextProperties().isCentered(true);chart.getChartTitle().setHeight(30);chart.hasTitle( true);DataTable dataTable = getDataTable();insertDatatableToChart(chart,dataTable);//set series label chart.getSeries().setSeriesLabel(chart.getChartData().get("B1","D1"));System.out.println(chart.getSeries().size());if (chartType.getName().contains("Scatter") || chartType.getName().contains("Bubble")){chart.getSeries().get(0).setXValues(chart.getChartData().get("A2","A7"));chart.getSeries().get(0).setYValues(chart.getChartData().get("B2","B7"));chart.getSeries().get(1).setYValues(chart.getChartData().get("C2","C7"));chart.getSeries().get(2).setYValues(chart.getChartData().get("D2","D7"));if (chartType.getName().contains("Bubble")){for (int i = 0;i <chart.getSeries().size();i++){chart.getSeries().get(i).getBubbles().add(1);chart.getSeries().get(i).getBubbles().add(4);chart.getSeries().get(i).getBubbles().add(3);chart.getSeries().get(i).getBubbles().add(4);chart.getSeries().get(i).getBubbles().add(2);chart.getSeries().get(i).getBubbles().add(9);}}}else{//set category label chart.getCategories().setCategoryLabels(chart.getChartData().get("A2","A7"));//set values for series chart.getSeries().get(0).setValues(chart.getChartData().get("B2","B7"));chart.getSeries().get(1).setValues(chart.getChartData().get("C2","C7"));chart.getSeries().get(2).setValues(chart.getChartData().get("D2","D7"));if (chartType.getName().contains("3D")){chart.getRotationThreeD().setXDegree(10);chart.getRotationThreeD().setYDegree(10);}}presentation.saveToFile(resultFilePath,FileFormat.PPTX_2013);}private DataTable getDataTable() throws Exception{DataTable dataTable = new DataTable();dataTable.getColumns().add(new DataColumn("SalesPers",DataTypes.DATATABLE_STRING));dataTable.getColumns().add(new DataColumn("SaleAmt",DataTypes.DATATABLE_INT));dataTable.getColumns().add(new DataColumn("ComPct",DataTypes.DATATABLE_INT));dataTable.getColumns().add(new DataColumn("ComAmt",DataTypes.DATATABLE_INT));DataRow row1 = dataTable.newRow();row1.setString("SalesPers","Joe");row1.setInt("SaleAmt",250);row1.setInt("ComPct",150);row1.setInt("ComAmt",99);DataRow row2 = dataTable.newRow();row2.setString("SalesPers","Robert");row2.setInt("SaleAmt",270);row2.setInt("ComPct",150);row2.setInt("ComAmt",99);DataRow row3 = dataTable.newRow();row3.setString("SalesPers","Michelle");row3.setInt("SaleAmt",310);row3.setInt("ComPct",120);row3.setInt("ComAmt",49);DataRow row4 = dataTable.newRow();row4.setString("SalesPers","Erich");row4.setInt("SaleAmt",330);row4.setInt("ComPct",120);row4.setInt("ComAmt",49);DataRow row5 = dataTable.newRow();row5.setString("SalesPers","Dafna");row5.setInt("SaleAmt",360);row5.setInt("ComPct",150);row5.setInt("ComAmt",141);DataRow row6 = dataTable.newRow();row6.setString("SalesPers","Rob");row6.setInt("SaleAmt",380);row6.setInt("ComPct",150);row6.setInt("ComAmt",135);dataTable.getRows().add(row1);dataTable.getRows().add(row2);dataTable.getRows().add(row3);dataTable.getRows().add(row4);dataTable.getRows().add(row5);dataTable.getRows().add(row6);return dataTable;}private void insertDatatableToChart(IChart chart,DataTable dataTable) throws Exception{for (int c = 0;c <dataTable.getColumns().size();c++){chart.getChartData().get(0,c).setText(dataTable.getColumns().get(c).getColumnName());}for (int r = 0;r <dataTable.getRows().size();r++){Object[] datas = dataTable.getRows().get(r).getArrayList();for (int c = 0;c <datas.length;c++){chart.getChartData().get(r + 1,c).setValue(datas[c]);}}}}
Tab 3
using Spire.Presentation;using Spire.Presentation.Charts;using System;using System.Data;using System.Drawing;namespace DemoOnlineCode{class CreateCharts{public void ChartDemo(String resultFileName,ChartType chartType){Presentation presentation = new Presentation();RectangleF rect1 = new RectangleF(90,100,550,320);IChart chart = presentation.Slides[0].Shapes.AppendChart(chartType,rect1,false);//chart title chart.ChartTitle.TextProperties.Text = "Chart";chart.ChartTitle.TextProperties.IsCentered = true;chart.ChartTitle.Height = 30;chart.HasTitle = true;DataTable dataTable = getDataTable();insertDatatableToChart(chart,dataTable);//set series label chart.Series.SeriesLabel = chart.ChartData["B1","D1"];if (chartType.ToString().Contains("Scatter") || chartType.ToString().Contains("Bubble")){chart.Series[0].XValues = chart.ChartData["A2","A7"];chart.Series[0].YValues = chart.ChartData["B2","B7"];chart.Series[1].XValues = chart.ChartData["A2","A7"];chart.Series[1].YValues = chart.ChartData["C2","C7"];chart.Series[2].XValues = chart.ChartData["A2","A7"];chart.Series[2].YValues = chart.ChartData["D2","D7"];if (chartType.ToString().Contains("Bubble")){for (int i = 0;i <chart.Series.Count;i++){chart.Series[i].Bubbles.Add(1);chart.Series[i].Bubbles.Add(4);chart.Series[i].Bubbles.Add(3);chart.Series[i].Bubbles.Add(4);chart.Series[i].Bubbles.Add(2);chart.Series[i].Bubbles.Add(9);}}}else{//set category label chart.Categories.CategoryLabels = chart.ChartData["A2","A7"];//set values for series chart.Series[0].Values = chart.ChartData["B2","B7"];chart.Series[1].Values = chart.ChartData["C2","C7"];chart.Series[2].Values = chart.ChartData["D2","D7"];if (chartType.ToString().Contains("3D")){chart.RotationThreeD.XDegree = 10;chart.RotationThreeD.YDegree = 10;}}presentation.SaveToFile(resultFileName+".pptx",FileFormat.Pptx2013);}private static DataTable getDataTable(){DataTable dataTable = new DataTable();dataTable.Columns.Add(new DataColumn("SalesPers",typeof(String)));dataTable.Columns.Add(new DataColumn("SaleAmt",typeof(Int32)));dataTable.Columns.Add(new DataColumn("ComPct",typeof(Int32)));dataTable.Columns.Add(new DataColumn("ComAmt",typeof(Int32)));dataTable.Rows.Add("Jeo",250,150,99);dataTable.Rows.Add("Robert",270,150,99);dataTable.Rows.Add("Michelle",310,120,49);dataTable.Rows.Add("Erich",330,120,49);dataTable.Rows.Add("Dafna",360,150,141);dataTable.Rows.Add("Rob",380,150,135);return dataTable;}private static void insertDatatableToChart(IChart chart,DataTable dataTable){for (int c = 0;c <dataTable.Columns.Count;c++){chart.ChartData[0,c].Text = dataTable.Columns[c].ColumnName;}for (int r = 0;r <dataTable.Rows.Count;r++){Object[] datas = dataTable.Rows[r].ItemArray;for (int c = 0;c <datas.Length;c++){chart.ChartData[r + 1,c].Value = datas[c];}}}}}