Drawing graphics (Vue)

This sample shows how to draw graphics on a page. Click the 'Export' button to view the exported PDF document.

For more information, see the Drawing Graphics topic in Documentation.

This example uses Vue.

<template> <div class="container-fluid"> <!-- Export button --> <button class="btn btn-default" @click="exportPDF">Export</button> </div> </template> <script> import 'bootstrap.css'; import Vue from 'vue'; import * as wijmo from '@grapecity/wijmo'; import * as pdf from '@grapecity/wijmo.pdf'; // let App = Vue.extend({ name: 'app', a: 100, // sample area's size. c1: new wijmo.Color('#3173c0'), c2: new wijmo.Color('#e69500'), methods: { exportPDF() { let doc = new pdf.PdfDocument({ header: { height: 0 }, footer: { height: 0 }, ended: (sender, args) => pdf.saveBlob(args.blob, 'Document.pdf') }); // this.$_sample1(doc); this.$_sample2(doc); this.$_sample3(doc); this.$_sample4(doc); this.$_sample5(doc); // doc.end(); }, $_sample1(doc) { doc.drawText('Draw a series of lines with different styles: '); // let y = doc.y + doc.lineHeight(), a = this.$options.a, c1 =this.$options.c1; // // default document's pen (black color) doc.paths .moveTo(0, y) .lineTo(a, y) .stroke(); // // color doc.paths .moveTo(0, y + 20) .lineTo(a, y + 20) .stroke(c1); // // color, line width = 3 doc.paths .moveTo(0, y + 40) .lineTo(a, y + 40) .stroke(new pdf.PdfPen(c1, 3)); // // opacity color, line width = 3 doc.paths .moveTo(0, y + 60) .lineTo(a, y + 60) .stroke(new pdf.PdfPen(wijmo.Color.fromRgba(c1.r, c1.g, c1.b, 0.2), 3)); // // color, dash pattern, line width = 3 doc.paths .moveTo(0, y + 80) .lineTo(a, y + 80) .stroke(new pdf.PdfPen(c1, 3, new pdf.PdfDashPattern(5))); // doc.y = y + a + doc.lineHeight(); }, $_sample2(doc) { doc.drawText('Draw a rectangle covered with a filled curved path:'); // let y = doc.y + doc.lineHeight(), a = this.$options.a, c1 =this.$options.c1, c2 =this.$options.c2; // doc.paths .rect(0, y, a, a) .stroke(c1); // doc.paths .moveTo(0, y) .bezierCurveTo(a / 2, y, a / 2, a + y, a, a + y) .lineTo(0, a + y) .lineTo(0, y) .fill(c2); // doc.y = y + a + doc.lineHeight(); }, $_sample3(doc) { doc.drawText('Draw a rectangle, inscribe a circle into it, fill the circle with an opaque color and stroke it using a dashed line:'); // let y = doc.y + doc.lineHeight(), a = this.$options.a, c1 =this.$options.c1, c2 =this.$options.c2; // doc.paths .rect(0, y, a, a) .fill(c1); // doc.paths .circle(a / 2, y + a / 2, a / 2) .fillAndStroke(wijmo.Color.fromRgba(c2.r, c2.g, c2.b, 0.3), new pdf.PdfPen(c2, 2, new pdf.PdfDashPattern(5))); // doc.y = y + a + doc.lineHeight(); }, $_sample4(doc) { doc.drawText('Draw a simple pattern clipped by a circular clipping path:'); // let y = doc.y + doc.lineHeight(), a = this.$options.a, c1 =this.$options.c1, c2 =this.$options.c2, a0 = 10; // doc.saveState(); // // clipping path doc.paths .circle(a / 2, y + a / 2, a / 2) .clip(); // // draw pattern for (let i = 0; i < 10; i++) { doc.paths .rect(0, y + i * a0, a, a0) .fill(i % 2 ? c1 : c2); } // doc.restoreState(); // doc.y = y + a + doc.lineHeight(); }, $_sample5(doc) { doc.drawText('Draw a series of rectangles and rotate every rectangle by 15 degrees to the previous:'); // let y = doc.y + doc.lineHeight(), sqrt2 = Math.sqrt(2), degrees = 15, samples = 90 / degrees, a = this.$options.a, c1 =this.$options.c1, c2 =this.$options.c2; // doc.saveState(); // for (let i = 0; i < samples; i++) { doc .rotate(degrees, new wijmo.Point(a / 2, y + a / 2)) .paths // draw rectangle as if it is inscribed into a circle with the radius of a/ 2 .rect((a - a / sqrt2) / 2, y + ((a - a / sqrt2) / 2), a / sqrt2, a / sqrt2) .fill(wijmo.Color.interpolate(c1, c2, i * (1 / (samples - 1)))); } // doc.restoreState(); // doc.y = y + a + doc.lineHeight(); } } }) // new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> body { margin-bottom: 24px; } </style>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Drawing Graphics</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } //'*.vue': { loader: 'systemjs-plugin-vue' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@grapecity/wijmo': 'npm:@grapecity/wijmo/index.js', '@grapecity/wijmo.input': 'npm:@grapecity/wijmo.input/index.js', '@grapecity/wijmo.styles': 'npm:@grapecity/wijmo.styles', '@grapecity/wijmo.cultures': 'npm:@grapecity/wijmo.cultures', '@grapecity/wijmo.chart': 'npm:@grapecity/wijmo.chart/index.js', '@grapecity/wijmo.chart.analytics': 'npm:@grapecity/wijmo.chart.analytics/index.js', '@grapecity/wijmo.chart.animation': 'npm:@grapecity/wijmo.chart.animation/index.js', '@grapecity/wijmo.chart.annotation': 'npm:@grapecity/wijmo.chart.annotation/index.js', '@grapecity/wijmo.chart.finance': 'npm:@grapecity/wijmo.chart.finance/index.js', '@grapecity/wijmo.chart.finance.analytics': 'npm:@grapecity/wijmo.chart.finance.analytics/index.js', '@grapecity/wijmo.chart.hierarchical': 'npm:@grapecity/wijmo.chart.hierarchical/index.js', '@grapecity/wijmo.chart.interaction': 'npm:@grapecity/wijmo.chart.interaction/index.js', '@grapecity/wijmo.chart.radar': 'npm:@grapecity/wijmo.chart.radar/index.js', '@grapecity/wijmo.chart.render': 'npm:@grapecity/wijmo.chart.render/index.js', '@grapecity/wijmo.chart.webgl': 'npm:@grapecity/wijmo.chart.webgl/index.js', '@grapecity/wijmo.gauge': 'npm:@grapecity/wijmo.gauge/index.js', '@grapecity/wijmo.grid': 'npm:@grapecity/wijmo.grid/index.js', '@grapecity/wijmo.grid.detail': 'npm:@grapecity/wijmo.grid.detail/index.js', '@grapecity/wijmo.grid.filter': 'npm:@grapecity/wijmo.grid.filter/index.js', '@grapecity/wijmo.grid.search': 'npm:@grapecity/wijmo.grid.search/index.js', '@grapecity/wijmo.grid.grouppanel': 'npm:@grapecity/wijmo.grid.grouppanel/index.js', '@grapecity/wijmo.grid.multirow': 'npm:@grapecity/wijmo.grid.multirow/index.js', '@grapecity/wijmo.grid.transposed': 'npm:@grapecity/wijmo.grid.transposed/index.js', '@grapecity/wijmo.grid.pdf': 'npm:@grapecity/wijmo.grid.pdf/index.js', '@grapecity/wijmo.grid.sheet': 'npm:@grapecity/wijmo.grid.sheet/index.js', '@grapecity/wijmo.grid.xlsx': 'npm:@grapecity/wijmo.grid.xlsx/index.js', '@grapecity/wijmo.grid.selector': 'npm:@grapecity/wijmo.grid.selector/index.js', '@grapecity/wijmo.grid.cellmaker': 'npm:@grapecity/wijmo.grid.cellmaker/index.js', '@grapecity/wijmo.nav': 'npm:@grapecity/wijmo.nav/index.js', '@grapecity/wijmo.odata': 'npm:@grapecity/wijmo.odata/index.js', '@grapecity/wijmo.olap': 'npm:@grapecity/wijmo.olap/index.js', '@grapecity/wijmo.pdf': 'npm:@grapecity/wijmo.pdf/index.js', '@grapecity/wijmo.viewer': 'npm:@grapecity/wijmo.viewer/index.js', '@grapecity/wijmo.xlsx': 'npm:@grapecity/wijmo.xlsx/index.js', '@grapecity/wijmo.undo': 'npm:@grapecity/wijmo.undo/index.js', '@grapecity/wijmo.interop.grid': 'npm:@grapecity/wijmo.interop.grid/index.js', '@grapecity/wijmo.touch': 'npm:@grapecity/wijmo.touch/index.js', '@grapecity/wijmo.cloud': 'npm:@grapecity/wijmo.cloud/index.js', "@grapecity/wijmo.vue2.chart.analytics": "npm:@grapecity/wijmo.vue2.chart.analytics/index.js", "@grapecity/wijmo.vue2.chart.animation": "npm:@grapecity/wijmo.vue2.chart.animation/index.js", "@grapecity/wijmo.vue2.chart.annotation": "npm:@grapecity/wijmo.vue2.chart.annotation/index.js", "@grapecity/wijmo.vue2.chart.finance.analytics": "npm:@grapecity/wijmo.vue2.chart.finance.analytics/index.js", "@grapecity/wijmo.vue2.chart.finance": "npm:@grapecity/wijmo.vue2.chart.finance/index.js", "@grapecity/wijmo.vue2.chart.hierarchical": "npm:@grapecity/wijmo.vue2.chart.hierarchical/index.js", "@grapecity/wijmo.vue2.chart.interaction": "npm:@grapecity/wijmo.vue2.chart.interaction/index.js", "@grapecity/wijmo.vue2.chart.radar": "npm:@grapecity/wijmo.vue2.chart.radar/index.js", "@grapecity/wijmo.vue2.chart": "npm:@grapecity/wijmo.vue2.chart/index.js", "@grapecity/wijmo.vue2.core": "npm:@grapecity/wijmo.vue2.core/index.js", "@grapecity/wijmo.vue2.gauge": "npm:@grapecity/wijmo.vue2.gauge/index.js", "@grapecity/wijmo.vue2.grid.detail": "npm:@grapecity/wijmo.vue2.grid.detail/index.js", "@grapecity/wijmo.vue2.grid.filter": "npm:@grapecity/wijmo.vue2.grid.filter/index.js", "@grapecity/wijmo.vue2.grid.grouppanel": "npm:@grapecity/wijmo.vue2.grid.grouppanel/index.js", '@grapecity/wijmo.vue2.grid.search': 'npm:@grapecity/wijmo.vue2.grid.search/index.js', "@grapecity/wijmo.vue2.grid.multirow": "npm:@grapecity/wijmo.vue2.grid.multirow/index.js", "@grapecity/wijmo.vue2.grid.sheet": "npm:@grapecity/wijmo.vue2.grid.sheet/index.js", '@grapecity/wijmo.vue2.grid.transposed': 'npm:@grapecity/wijmo.vue2.grid.transposed/index.js', "@grapecity/wijmo.vue2.grid": "npm:@grapecity/wijmo.vue2.grid/index.js", "@grapecity/wijmo.vue2.input": "npm:@grapecity/wijmo.vue2.input/index.js", "@grapecity/wijmo.vue2.olap": "npm:@grapecity/wijmo.vue2.olap/index.js", "@grapecity/wijmo.vue2.viewer": "npm:@grapecity/wijmo.vue2.viewer/index.js", "@grapecity/wijmo.vue2.nav": "npm:@grapecity/wijmo.vue2.nav/index.js", "@grapecity/wijmo.vue2.base": "npm:@grapecity/wijmo.vue2.base/index.js", 'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.js', //'systemjs-plugin-vue': 'npm:systemjs-plugin-vue/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, wijmo: { defaultExtension: 'js', } } }); })(this);