|
| 1 | +# Simple Chart with Webpack and NPM |
| 2 | + |
| 3 | +This is the simplest project using SciChart.js as npm module and Webpack. |
| 4 | + |
| 5 | +## How to run the project |
| 6 | + |
| 7 | +* `npm install` |
| 8 | +* `npm start` |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Description |
| 13 | + |
| 14 | +### webpack.config.js |
| 15 | + |
| 16 | +Use CopyPlugin to copy wasm and data files and serve them by webpack-dev-server. SciChart.js uses WebAssembly and those files **scichart2d.data**, **scichart2d.wasm** must be loaded. |
| 17 | + |
| 18 | +```javascript |
| 19 | +const path = require('path'); |
| 20 | +const CopyPlugin = require("copy-webpack-plugin"); |
| 21 | + |
| 22 | +module.exports = { |
| 23 | + mode: 'development', |
| 24 | + entry: "./src/index.js", |
| 25 | + performance: { |
| 26 | + hints: false |
| 27 | + }, |
| 28 | + output: { |
| 29 | + path: path.resolve(__dirname, 'build'), |
| 30 | + filename: 'bundle.js', |
| 31 | + }, |
| 32 | + plugins: [ |
| 33 | + new CopyPlugin({ |
| 34 | + patterns: [ |
| 35 | + { from: "src/index.html", to: "" }, |
| 36 | + { from: "node_modules/scichart/_wasm/scichart2d.data", to: "" }, |
| 37 | + { from: "node_modules/scichart/_wasm/scichart2d.wasm", to: "" } |
| 38 | + ] |
| 39 | + }) |
| 40 | + ] |
| 41 | +}; |
| 42 | +``` |
| 43 | + |
| 44 | +### SciChartSurface.configure |
| 45 | + |
| 46 | +You may need this to configure from where wasm and data files are served, update `src/index.js` file if needed |
| 47 | + |
| 48 | +```javascript |
| 49 | +import { SciChartSurface } from "scichart/Charting/Visuals/SciChartSurface"; |
| 50 | + |
| 51 | +// call this before SciChartSurface.create() |
| 52 | +SciChart.SciChartSurface.configure({ dataUrl: "/custom/scichart2d.data", wasmUrl: "/other/scichart2d.wasm" }); |
| 53 | +``` |
| 54 | + |
| 55 | +### Chart div element |
| 56 | + |
| 57 | +If you call `SciChartSurface.create("scichart-root")` an element with Id "scichart-root" must be present. |
| 58 | + |
| 59 | +```html |
| 60 | +<html lang="en-us"> |
| 61 | + <head> |
| 62 | + <meta charset="utf-8" /> |
| 63 | + <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> |
| 64 | + <title>SciChart.js Tutorial 1</title> |
| 65 | + <script async type="text/javascript" src="bundle.js"></script> |
| 66 | + </head> |
| 67 | + <body> |
| 68 | + <!-- the Div where the SciChartSurface will reside --> |
| 69 | + <div id="scichart-root" style="width: 800px; height: 600px;"></div> |
| 70 | + </body> |
| 71 | +</html> |
| 72 | +``` |
0 commit comments