Run
Auto Run
const chartColors = [ 'rgb(255, 99, 132)', 'rgb(255, 159, 64)', 'rgb(255, 205, 86)', 'rgb(75, 192, 192)', 'rgb(54, 162, 235)', 'rgb(153, 102, 255)', 'rgb(201, 203, 207)' ] define('my-app', class extends WeElement { install(){ this.chartData = { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], backgroundColor: Chart.helpers.color(chartColors[0]).alpha(0.2).rgbString(), borderColor: chartColors[0], borderWidth: 1 }] } this.chartOptions = { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } } onClick = ()=>{ this.chartData.datasets.forEach(dataset => { dataset.data.forEach((item, index) => { dataset.data[index] = Math.random() * 20 }) }) this.update() } addDataset = ()=>{ this.chartData.datasets.push({ type: 'line', label: '# of Votes', data: [Math.random()*20, Math.random()*20, Math.random()*20, Math.random()*20, Math.random()*20, Math.random()*20], backgroundColor: Chart.helpers.color(chartColors[this.chartData.datasets.length%6]).alpha(0.2).rgbString(), borderColor: chartColors[this.chartData.datasets.length%6], borderWidth: 1 }) this.update() } render(props, data) { return (
Change data
Add dataset
) } }) render(
, 'body')