Giter VIP home page Giter VIP logo

Comments (6)

pietersv avatar pietersv commented on July 20, 2024

@alexleventer It is possible to create a bar chart. See examples/make_pptx.js for a few examples. For your immediate purpose, use the more general slide.makeChart(..) and set renderType: 'bar' on the object you pass to it:

slide.addChart({
     title: 'Sample bar chart',
     renderType: 'bar', 
     data: [...]
 }, null, doneCallback, errorCallback);

Thanks for catching the issue with the convenience methods. Will fix that and the docs, and these to the nascent test files

from officegen.

alexleventer avatar alexleventer commented on July 20, 2024

Thanks for the quick response @pietersv , do I first have to make the chart and then add chart?

from officegen.

alexleventer avatar alexleventer commented on July 20, 2024

Looks like NPM module is out of date w/ the repo

from officegen.

alexleventer avatar alexleventer commented on July 20, 2024

and the latest npm release includes setWidescreen but this repo does not.

from officegen.

pietersv avatar pietersv commented on July 20, 2024

aha. there's an outstanding pull request. For now try npm install pietersv/officegen to install directly from GitHub. Below is a complete example that should work.

var fs = require('fs');
var officegen = require('../');
    var chartInfo = {
      title: 'Sample bar chart',
      renderType: 'bar',
      xmlOptions: {
        "c:title": {
          "c:tx": {
            "c:rich": {
              "a:p": {
                "a:r": {
                  "a:t": "Override title via XML"
                }
              }
            }
          }
        }
      },
      data: [
        {
          name: 'europe',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [2.5, 2.6, 2.8],
          color: 'ff0000'
        },
        {
          name: 'namerica',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [2.5, 2.7, 2.9],
          color: '00ff00'
        },
        {
          name: 'asia',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [2.1, 2.2, 2.4],
          color: '0000ff'
        },
        {
          name: 'lamerica',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [0.3, 0.3, 0.3],
          color: 'ffff00'
        },
        {
          name: 'meast',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [0.2, 0.3, 0.3],
          color: 'ff00ff'
        },
        {
          name: 'africa',
          labels: ['Y2003', 'Y2004', 'Y2005'],
          values: [0.1, 0.1, 0.1],
          color: '00ffff'
        }

      ]
    };

    var chartIdx = 3;
    var pptx = officegen('pptx');
    pptx.setDocTitle('Sample PPTX Document');
    var slide = pptx.makeNewSlide();
    slide.name = 'OfficeChart slide';
    slide.back = 'ffffff';

    slide.addChart(
        chartInfo,
        null,
        function () {
          var FILENAME = "test-ppt-chart" + chartIdx + ".pptx";
          var FILENAME_ALT = "test-ppt-chart-" + chartInfo.renderType + ".pptx";
          var out = fs.createWriteStream('/tmp/' + FILENAME_ALT);
          pptx.generate(out, {
            'finalize': function (written) {
              console.log("Done!")
            },
            'error': console.error
          });
        },  console.error);

from officegen.

pietersv avatar pietersv commented on July 20, 2024

@alexleventer Glad to hear that worked. I've just updated the fork https://github.com/pietersv/officegen as follows:

  • Changed slide.addChart( info, renderType, success, error) to slide.addChart( info, success, error)
  • Dropped convenience methods addBarChart(), addPieChart() and addColumnChart()
  • Updated README.md, examples/make_pptx.js and test/test_pptx.js accordingly

The gist is that the renderType (i.e. bar, pie, column, group-bar) was specified in two places, either within the chartInfo object and/or the arguments to addChart(). Have dropped the latter, so its only specified in the chartInfo object now.

from officegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.