This may or may not be a viable solution for you, but I gave up on Plotly and the Chart component a long time ago and moved to using chart.js in a custom component. ChatGPT is great about suggesting changes to the config if I want to do something different.
Here is my iFrame code:
<style>
body {
margin: 0;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!--<script src="https://www.chartjs.org/samples/latest/utils.js"></script>-->
<script>
window.Retool.subscribe(function(model) {
if (!model) { return }
model.options.tooltips['callbacks'] = {
footer: function(tooltipItems, data) {
var sum = 0;
tooltipItems.forEach(function(tooltipItem) {
sum += data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
});
return sum;
}
};
var chartData = model.data;
var ctx = document.getElementById('canvas').getContext('2d');
if (!window.myMixedChart) {
window.myMixedChart = new Chart(ctx, model);
} else {
window.myMixedChart.data = model.data;
window.myMixedChart.options = model.options;
window.myMixedChart.update();
}
})
</script>
<div class="chart-container" style="position: relative;margin: auto; height:100vh; width:100vw;">
<canvas id="canvas"></canvas>
</div>
</body>
</html>
Here is my model:
{
type: "line",
options: {
responsive: true,
stacked: true,
maintainAspectRatio: false,
title: {text: "sample horizontal stacked",display: true},
tooltips: {mode: "index", intersect: true},
legend: {position: "bottom"},
scales: {
x: {
stacked: false,
},
y: {
stacked: false
}
}
},
data: {
labels: {{Stats_Inquiry_By_Category.data.week_start}},
datasets: {{GraphSource_InquiryCategrories.value.datasets}}
}
}
My labels looks like this:
[
"2024-01-15",
"2024-01-22",
"2024-01-29",
"2024-02-05",
"2024-02-12"
]
My datasets
object looks like this:
{
"categories": [
"Google",
"Yelp",
"Word_of_Mouth",
"Other",
"Website",
"Email"
],
"datasets": [
{
"label": "Google",
"data": [
"0",
"1",
"1",
"0",
"0"
],
"backgroundColor": "rgb(231,95,10)"
},
{
"label": "Yelp",
"data": [
"0",
"1",
"0",
"2",
"0"
],
"backgroundColor": "rgb(231,95,112)"
},
{
"label": "Website",
"data": [
"3",
"7",
"0",
"0",
"0"
],
"backgroundColor": "rgb(230,171,2)"
},
{
"label": "Word_of_Mouth",
"data": [
"0",
"0",
"0",
"0"
],
"backgroundColor": "rgb(56,108,176)"
},
{
"label": "Other",
"backgroundColor": "rgb(77,192,77)"
},
{
"label": "Other",
"data": [
"1",
"1",
"0",
"0",
"0"
],
"backgroundColor": "rgb(77,77,77)"
}
]
}
Here is what is looks like:
You do need to create the proper structures, but I also needed to do that on plotly.