Last active
November 7, 2017 01:15
-
-
Save 3cp/026a9954808745b9887d7dfca041d4cb to your computer and use it in GitHub Desktop.
highchart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <require from="./line-chart"></require> | |
| <button click.trigger="doAgain()">New data</button> | |
| <line-chart charges.bind="charges"></line-chart> | |
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class App { | |
| charges = [{x: 1, y: 3.2}, {x: 2, y: 2.1}, {x:3, y: 4.9}]; | |
| doAgain() { | |
| this.charges = [ | |
| {x: 1, y: Math.random() * 10}, | |
| {x: 2, y: Math.random() * 10}, | |
| {x: 3, y: Math.random() * 10}, | |
| ]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Aurelia</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| </head> | |
| <body aurelia-app> | |
| <h1>Loading...</h1> | |
| <script src="https://code.highcharts.com/highcharts.js"></script> | |
| <script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
| <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
| <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
| <script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
| <script> | |
| require(['aurelia-bootstrapper']); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* global Highcharts */ | |
| import {bindable, inlineView, computedFrom} from 'aurelia-framework'; | |
| @inlineView(` | |
| <template ref="el"> | |
| </template> | |
| `) | |
| export class LineChart { | |
| @bindable charges; | |
| attached() { | |
| this.updateChart(); | |
| } | |
| detached() { | |
| this.destroyChart(); | |
| } | |
| destroyChart() { | |
| if (this.chart) { | |
| this.chart.destroy(); | |
| this.chart = null; | |
| } | |
| } | |
| updateChart() { | |
| this.destroyChart(); | |
| const highchartsOptions = this.highchartsOptions(); | |
| this.chart = Highcharts.chart(this.el, highchartsOptions); | |
| } | |
| chargesChanged(newValue, oldValue) { | |
| // only update chart after first attached() | |
| if (this.chart) { | |
| this.updateChart(); | |
| } | |
| } | |
| highchartsOptions() { | |
| const {charges} = this; | |
| const series = [{ | |
| name: 'Charges', | |
| data: charges, | |
| }]; | |
| return { | |
| chart: { | |
| type: 'spline', | |
| height: 300, | |
| }, | |
| title: { | |
| text: null | |
| }, | |
| series, | |
| credits: { | |
| enabled: false | |
| }, | |
| legend: { | |
| enabled: true, | |
| verticalAlign: "bottom" | |
| } | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment