<div class="chart-container"></div>
<script>
const data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: 'My First Dataset',
data: [65, 59, 80, 81, 56, 55, 40],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
};
const options = {
};
const container = document.querySelector('.chart-container');
const canvas = document.createElement("CANVAS");
canvas.setAttribute('data-controller', 'chart');
canvas.setAttribute('data-chart-type-value', 'line');
canvas.setAttribute('data-chart-data-value', JSON.stringify(data));
canvas.setAttribute('data-chart-options-value', JSON.stringify(options));
// Stimulus will use chart_controller to init the chart
container.appendChild(canvas);
</script>
def line(self, **kwargs):
template = Template(
"""
<div class="chart-container"></div>
<script>
const data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: 'My First Dataset',
data: [65, 59, 80, 81, 56, 55, 40],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
};
const options = {
};
const container = document.querySelector('.chart-container');
const canvas = document.createElement("CANVAS");
canvas.setAttribute('data-controller', 'chart');
canvas.setAttribute('data-chart-type-value', 'line');
canvas.setAttribute('data-chart-data-value', JSON.stringify(data));
canvas.setAttribute('data-chart-options-value', JSON.stringify(options));
// Stimulus will use chart_controller to init the chart
container.appendChild(canvas);
</script>
""",
)
return template.render(Context({}))