C# 创建PPT图表
2021-07-10 20:08
标签:不显示 append dax 数字 安装路径 c++ 图表 标签 log 使用工具:Spire.Presentation for .NET 调试运行程序后,生成图表,如下图: 环形图创建效果: 图表创建结果: C# 创建PPT图表 标签:不显示 append dax 数字 安装路径 c++ 图表 标签 log 原文地址:http://blog.51cto.com/eiceblue/2176675
PS:下载安装后,注意添加引用Spire.Presentation.dll到程序,dll文件可在安装路径下的Bin文件夹中获取。【示例 1 】创建柱形图表
using Spire.Presentation;
using Spire.Presentation.Charts;
using System;
using System.Drawing;
namespace ColumnChart
{
class Program
{
static void Main(string[] args)
{
//创建一个PowerPoint文档
Presentation presentation = new Presentation();
//插入柱形图
RectangleF rect = new RectangleF(40, 50, 680, 500);
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.Column3DClustered, rect);
//添加图表名
chart.ChartTitle.TextProperties.Text = "2018年上半年销量";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//定义一个sting[,]数组
string[,] data = new string[,]
{
{"产品大类","1月","2月","3月","4月","5月","6月" },
{"DW10","1542","1057","1223","1302","1145","1336"},
{"ZQ13","4587","3658","2515","3154","2984","3890" },
{"YI73","558","458","369","576","334","482" },
{"TR11","2011","2485" ,"3010" ,"2785" ,"2225" ,"2476" }
};
//将数据写入图表后台数据表
for (int i = 0; i
【示例 2 】创建环形图表
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace DoughnutChart
{
class Program
{
static void Main(string[] args)
{
//创建一个PowerPoint文件
Presentation presentation = new Presentation();
//插入圆环图
RectangleF rect = new RectangleF(40, 100, 550, 320);
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.Doughnut, rect, false);
//设置图表名
chart.ChartTitle.TextProperties.Text = "市场份额";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//定义数据
string[] countries = new string[] { "古巴", "墨西哥", "法国", "德国" };
int[] sales = new int[] { 1800, 3000, 5100, 6200 };
//将数据写入图表后台数据表
chart.ChartData[0, 0].Text = "国家";
chart.ChartData[0, 1].Text = "销售额";
for (int i = 0; i
【示例 3 】创建混合型图表
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Data;
using System.Drawing;
namespace 混合图表
{
class Program
{
static void Main(string[] args)
{
//新建一个PowerPoint文档
Presentation presentation = new Presentation();
//插入柱形图
RectangleF rect = new RectangleF(40, 100, 650, 320);
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);
//添加表名
chart.ChartTitle.TextProperties.Text = "2017季度销售情况";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//创建一个DataTable
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("季度", Type.GetType("System.String")));
dataTable.Columns.Add(new DataColumn("销售额", Type.GetType("System.Int32")));
dataTable.Columns.Add(new DataColumn("同比增长率", Type.GetType("System.Decimal")));
dataTable.Rows.Add("1季度", 200, 0.6);
dataTable.Rows.Add("2季度", 250, 0.8);
dataTable.Rows.Add("3季度", 300, 0.6);
dataTable.Rows.Add("4季度", 150, 0.2);
//将DataTable数据导入图表后台数据表
for (int c = 0; c
注:Spire.Presentation 支持创建多大73种不同的图表样式,如下图
以上是本次关于“C# 创建PPT图表”的全部内容。
如需转载,请注明出处。