Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chart support for powerpoint slide #17

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
out.*
36 changes: 36 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = function(grunt) {
var path = require("path");
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
coffee: {
dynamic_mappings: {
expand: true,
flatten: false,
cwd: 'src/',
src: ['**/*.coffee'],
dest: 'lib/',
ext: '.js'
}
},

watch: {
coffee: {
files: ['src/*.coffee'],
tasks: 'coffee'
},
}
});

grunt.event.on('watch', function(action, filepath, target) {
console.log(filepath);
grunt.config(['coffee', 'dynamic_mappings', 'files', 'src'], filepath);
} );

// Load the plugin that provides the "less" task.

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-coffee');

grunt.registerTask('default', ['coffee:dynamic_mappings', 'watch']);
};
115 changes: 111 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# officegen #
# officegen-2 #

- by vtloc -

This module were built up-on the original module officegen which weren't published by me.
In this module, I've support the feature of exporting chart ( pie, bar, column ).
But the code is a bit hacky, that's why I've published this module separately.
Used it for your own risks.

- end by vtloc -

This module can generate Office Open XML files (the files been created by Microsoft Office 2007 and later).
This module is not depend on any framework so you can use it for any kind of node.js application, even not
Expand Down Expand Up @@ -37,6 +46,7 @@ Please refer to the roadmap section for information on what will be added in the
- Can declare fonts, alignment, colors and background.
- Support shapes: Ellipse, Rectangle, Line, Arrows, etc.
- Support hidden slides.
- Support
- Generating Microsoft Word document (.docx file):
- Create Word document.
- You can add one or more paragraphs to the document and you can set the fonts, colors, alignment, etc.
Expand All @@ -50,20 +60,22 @@ Please refer to the roadmap section for information on what will be added in the
via Git:

```bash
$ git clone git://github.com/Ziv-Barber/officegen.git
$ git clone git://github.com/vtloc/officegen.git
```

via npm:

```bash
$ npm install officegen
$ npm install officegen-2
```

This module is depending on:

- archiver
- setimmediate
- fast-image-size
- underscore
- xmlbuilder

<a name="a3"/>
## Public API: ##
Expand Down Expand Up @@ -260,6 +272,9 @@ The slide object supporting the following methods:
- addText ( text, options )
- addShape ( shape, options )
- addImage ( image, options )
- addPieChart ( data )
- addColumnChart ( data )
- addBarChart ( data )

Read only methods:

Expand Down Expand Up @@ -371,6 +386,94 @@ slide.addText ( 'Boom!!!', {
font_face: 'Wide Latin', font_size: 54,
color: 'cc0000', bold: true, underline: true } );
```
Examples how to add chart into the slide:
```js
// Column chart
slide = pptx.makeNewSlide();
slide.name = 'Chart slide';
slide.back = 'ffffff';
slide.addColumnChart(
{ title: 'Column chart',
data: [ // each item is one serie
{
name: 'Income',
labels: ['2005', '2006', '2007', '2008', '2009'],
values: [23.5, 26.2, 30.1, 29.5, 24.6],
color: 'ff0000' // optional
},
{
name: 'Expense',
labels: ['2005', '2006', '2007', '2008', '2009'],
values: [18.1, 22.8, 23.9, 25.1, 25],
color: '00ff00' // optional
}]
}
)

// Pie chart
slide = pptx.makeNewSlide();
slide.name = 'Pie Chart slide';
slide.back = 'ffff00';
slide.addPieChart(
{ title: 'My production',
data: [ // each item is one serie
{
name: 'Oil',
labels: ['Czech Republic', 'Ireland', 'Germany', 'Australia', 'Austria', 'UK', 'Belgium'],
values: [301, 201, 165, 139, 128, 99, 60],
colors: ['ff0000', '00ff00', '0000ff', 'ffff00', 'ff00ff', '00ffff', '000000'] // optional
}]
}
)

// Bar Chart
slide = pptx.makeNewSlide();
slide.name = 'Bar Chart slide';
slide.back = 'ff00ff';
slide.addBarChart(
{ title: 'Sample bar chart',
data: [ // each item is one serie
{
name: 'europe',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.5, 2.6, 2.8],
color: 'ff0000' // optional
},
{
name: 'namerica',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.5, 2.7, 2.9],
color: '00ff00' // optional
},
{
name: 'asia',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.1, 2.2, 2.4],
color: '0000ff' // optional
},
{
name: 'lamerica',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.3, 0.3, 0.3],
color: 'ffff00' // optional
},
{
name: 'meast',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.2, 0.3, 0.3],
color: 'ff00ff' // optional
},
{
name: 'africa',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.1, 0.1, 0.1],
color: '00ffff' // optional
}

]
}
)
```

#### Word: ####

Expand Down Expand Up @@ -474,7 +577,11 @@ https://groups.google.com/forum/?fromgroups#!forum/node-officegen

<a name="a8"/>
## History: ##

- Version 0.3.*:
- PowerPoint:
- Add pie chart
- Add bar chart
- Add column chart
- Version 0.2.6:
- PowerPoint:
- Automatically support line breaks.
Expand Down
Loading