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, 5, 3], stack: 'Stack 0', backgroundColor: Chart.helpers.color(chartColors[0]).alpha(0.2).rgbString(), borderColor: chartColors[0], borderWidth: 1 },{ label: '# of Votes', data: [7, 17, 13, 5, 12, 13], stack: 'Stack 0', backgroundColor: Chart.helpers.color(chartColors[3]).alpha(0.2).rgbString(), borderColor: chartColors[3], borderWidth: 1 },{ label: '# of Votes', data: [12, 7, 6, 5, 9, 7], stack: 'Stack 1', backgroundColor: Chart.helpers.color(chartColors[1]).alpha(0.2).rgbString(), borderColor: chartColors[1], borderWidth: 1 } ] } this.chartOptions = { title: { display: true, text: 'Omi-chart Bar Chart - Stacked' }, tooltips: { mode: 'index', intersect: false }, responsive: true, scales: { xAxes: [{ stacked: true, }], yAxes: [{ stacked: true }] } } } onClick = ()=>{ this.chartData.datasets.forEach((dataset, index) => { dataset.data.forEach((item, subIndex) => { dataset.data[subIndex] = Math.random() * 100 }) }) this.update() } render(props, data) { return (
Change data
) } }) render(
, 'body')