Created
October 20, 2023 07:47
-
-
Save rg3915/fb795692402e15f55192b7620aa5f467 to your computer and use it in GitHub Desktop.
Django and ChartJS load data chartjs 2023 json parse data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ctx = document.getElementById('grafico') | |
const labels = JSON.parse('{{ labels|safe }}') | |
const data = JSON.parse('{{ data|safe }}') | |
new Chart(ctx, { | |
type: 'line', | |
data: { | |
labels: labels, | |
datasets: [{ | |
label: 'The quick brown fox jumps over the lazy dog', | |
data: data, | |
borderWidth: 1 | |
}] | |
}, | |
options: { | |
responsive: true, | |
maintainAspectRatio: false, | |
scales: { | |
y: { | |
beginAtZero: false | |
} | |
} | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
labels = json.dumps([item.title for item in items]) | |
data = json.dumps([float(item.value) for item in items]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment