Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
Passing Django view data to JavaScript Chart

I have some data that is returned via Django view, I'm trying to render the data in an Apex Pie Chart.

So I need to pass the data into JavaScript as this is where the data series is.

var pieColors = getChartColorsArray("#pie_chart"),
    options = {
        chart: {
            height: 320,
            type: "pie"
        },
        series: [44, 55, 41, 17, 15],
        labels: ["Series 1", "Series 2", "Series 3", "Series 4", "Series 5"],
        colors: pieColors,
        legend: {
            show: !0,
            position: "bottom",
            horizontalAlign: "center",
            verticalAlign: "middle",
            floating: !1,
            fontSize: "14px",
            offsetX: 0
        },
        responsive: [{
            breakpoint: 600,
            options: {
                chart: {
                    height: 240
                },
                legend: {
                    show: !1
                }
            }
        }]
    };
(chart = new ApexCharts(document.querySelector("#pie_chart"), options)).render();

How do I pass the data in as it needs to be dynamic in the sense that the data in the pie chart could change based on other actions within the app?

Should just embed the JS into my HTML template and then set the series values to

series: [{{ value.1 }}, {{ value.2 }}, ...],

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you are using <script> block in your html template, you can pass context data

series: [{{value.1}}, {{value.1}}...],

or

series: [ 
         {% for value in data %}
             {{value}},
         {% endfor %}
],

other way is adding variable in html template, then you are able to use 'values' inside script.js file

<script>
var values = JSON.parse("[{{value.1}}, {{value.2}},]")
</script>
<script src="{% static 'js/script.js' %}"></script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda