JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "Stacked Column 100"
},
subtitles: [{
text: "Click On DataPoints to Swap"
}],
data: [{
type: "stackedColumn100",
click: updateSeries,
dataPoints: [
{ y: 50 }
]
},{
type: "stackedColumn100",
click: updateSeries,
dataPoints: [
{ y: 71 }
]
},{
type: "stackedColumn100",
click: updateSeries,
dataPoints: [
{ y: 65 }
]
},{
type: "stackedColumn100",
click: updateSeries,
dataPoints: [
{ y: 60 }
]
},{
type: "stackedColumn100",
click: updateSeries,
dataPoints: [
{ y: 48 }
]
}]
});
chart.render();
function updateSeries(e) {
var temp = e.chart.options.data[e.dataSeriesIndex];
if(e.dataSeriesIndex < e.chart.data.length - 1) {
e.chart.options.data[e.dataSeriesIndex] = e.chart.options.data[e.dataSeriesIndex + 1];
e.chart.options.data[e.dataSeriesIndex + 1] = temp;
}
e.chart.render();
}