churnRate = (transitions, states, title) => {
const container = html`<canvas></canvas>`;
const myChart = new Chart(container, {
type: 'line',
data: {
labels: transitions.map((t) => dateDiffToHuman(t.date)),
datasets: [{
data: transitions.map(({ transitions }) => Math.floor(transitions['Lapsed High-Value'] / (transitions['Lapsed High-Value'] + transitions['High-Value'] + transitions['High to Low-Value']) * 100)),
fill: false,
label: 'Lapsed High-Value',
borderColor: color.red,
lineTension: 0,
borderWidth: 3,
yAxisID: 'A',
}, {
data: transitions.map(({ transitions }) => Math.floor(transitions['High to Low-Value'] / (transitions['High to Low-Value'] + transitions['High-Value'] + transitions['Lapsed High-Value']) * 100)),
fill: false,
label: 'High to Low-Value',
borderColor: color.orange,
lineTension: 0,
borderWidth: 3,
yAxisID: 'A',
}, {
type: 'bar',
data: states.map(({ states }) => states.high),
label: 'High-Value Users',
backgroundColor: colorMap['High-Value'],
borderWidth: 3,
yAxisID: 'B',
}]
},
options: {
title: {
display: true,
text: title
},
scales: {
yAxes: [{
id: 'B',
ticks: {
min: 0
},
scaleLabel: {
display: true,
labelString: 'High-Value User Volume',
},
gridLines: {
display: false
},
}, {
id: 'A',
ticks: {
callback: (value) => `${value}%`,
},
position: 'right',
gridLines: {
zeroLineColor: 'black'
},
scaleLabel: {
display: true,
labelString: 'Churn Rate',
},
}],
}
},
});
return container;
}