Chart module for docxtemplater.
this module has only simple usage yet, contact me on [email protected] or @prog666 in telegram if you want to help me with this
You will need docxtemplater v1: npm install docxtemplater
install this modile: npm install docxtemplater-chart-module
Your docx should contain the text: {$chart}
var fs = require('fs');
var ChartModule = require(‘docxtemplater-chart-module’);
var chartModule = new ChartModule();
var docx = new DocxGen()
.attachModule(chartModule)
.load(content)
.setData({
chart: {
lines: [
{
name: 'line 1',
data: [
{
x: 'day 1',
y: '4.3'
},
{
x: 'day 2',
y: '2.5'
},
{
x: 'day 3',
y: '3.5'
}
]
},
{
name: 'line 2',
data: [
{
x: 'day 1',
y: '2.4'
},
{
x: 'day 2',
y: '4.4'
},
{
x: 'day 3',
y: '1.8'
}
]
}
]
}
})
.render();
var buffer = docx
.getZip()
.generate({type:"nodebuffer"});
fs.writeFile("test.docx", buffer);
defaultOptions = {
width: 5486400 / 9525,
height: 3200400 / 9525,
grid: true,
border: true,
title: false,
legend: {
position: 'r', // 'l', 'r', 'b', 't'
},
axis: {
x: {
orientation: 'minMax', // 'maxMin'
min: undefined, // number
max: undefined,
type: undefined, // 'date'
date: {
format: 'unix',
code: 'mm/yy', // "m/yy;@"
unit: 'months', // "days"
step: '1'
}
},
y: {
orientation: 'minMax',
mix: undefined,
max: undefined
}
}
}
You can build the coffee into js by running gulp
(this will watch the directory for changes)
You can test that everything works fine using the command mocha
. This will also create 3 docx files under the root directory that you can open to check if the docx are correct
- Border option, enabled by default
- bug fixes
- title option, disabled by default
- steps for date type
- type 'date' support
- time format in 'unix' or '1900' (amount of days since 1900)
- units for steps on axis
- formatCode for like i.e: 'd/m/yy' or 'm/yyyy'
- grid option
- lines on axis are still stacking, sadly
- x and y axises flipped in options, now correct
- min and max axis values options added
- options are nested now for easier readability