JavaScript
var chart1 = new CanvasJS.Chart("chartContainer1", {
title:{
text: "Frequency"
},
subtitles: [{
text: "times seen in 2019"
}],
axisX2: {
reversed: true,
lineThickness: 0,
tickLength: 0,
labelFormatter: function(e) {
return "";
}
},
axisY: {
reversed: true,
tickLength: 0,
gridThickness: 0,
labelFormatter: function(e) {
return "";
}
},
data: [{
type: "stackedBar100",
axisXType: "secondary",
indexLabel: "{y}",
indexLabelFontColor: "#ffffff",
color: "#A10102",
dataPoints: [
{ x: 1, y: 12 },
{ x: 2, y: 20 },
{ x: 3, y: 7 },
{ x: 4, y: 13 },
{ x: 5, y: 19 },
{ x: 6, y: 11 },
{ x: 7, y: 8 },
{ x: 8, y: 11 },
{ x: 9, y: 10 },
{ x: 10, y: 12 }
]
}
]
});
chart1.render();
addNewDataSeries(chart1, "Times in 2019");
var chart2 = new CanvasJS.Chart("chartContainer2", {
title:{
text: "Days Ago"
},
subtitles: [{
text: "when was last seen"
}],
axisX: {
reversed: true,
tickLength: 15,
tickThickness: 0
},
axisY: {
tickLength: 0,
gridThickness: 0,
labelFormatter: function(e) {
return "";
}
},
data: [{
type: "stackedBar100",
indexLabel: "{y}",
indexLabelFontColor: "#ffffff",
color: "#A10102",
dataPoints: [
{ x: 1, y: 31 },
{ x: 2, y: 25 },
{ x: 3, y: 10 },
{ x: 4, y: 25 },
{ x: 5, y: 35 },
{ x: 6, y: 28 },
{ x: 7, y: 18 },
{ x: 8, y: 4 },
{ x: 9, y: 14 },
{ x: 10, y: 24 }
]
}]
});
chart2.render();
addNewDataSeries(chart2, "days ago");
function addNewDataSeries(chart,indexLabelText){
var noOfDataSeries = chart.options.data.length;
for(var i=0; i<noOfDataSeries; i++){
chart.options.data.push({
type: "stackedBar100",
axisXType: chart.data[i].axisXType,
indexLabel: indexLabelText,
indexLabelPlacement: "outside",
color: "#EAEBF0",
...