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 = { maintainAspectRatio: true, spanGaps: false, elements: { line: { tension: 0.000001 } }, plugins: { filler: { propagate: false }, 'samples-filler-analyser': { target: 'chart-analyser' } } } } onClick = ()=> { this.chartData.datasets.forEach(dataset => { dataset.data.forEach((item, index) => { dataset.data[index] = Math.random() * 100 }) }) this.update() } addDataset = ()=>{ this.chartData.datasets.push({ label: '# of Votes', data: [Math.random()*100, Math.random()*100, Math.random()*100, Math.random()*100, Math.random()*100, Math.random()*100], 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')