Home chart.js data wont update
Reply: 1

chart.js data wont update

Mochamad Ramdanny Lukman
Mochamad Ramdanny Lukman Published in 2018-02-14 02:24:07Z

im trying to fetch data with ajax request to update chart.js. the ajax request is fine. but the response wont update the chart. this is how i fetch data :

<script type="text/javascript">
        var periode = $("select[name='tahun']").val();
            url:"<?php echo site_url('laporan/get_keuntungan/')?>"+periode,
                var graph = data;
                    data: {
                        labels: ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli","Agustus",'September','Oktober','November','Desember'],
                        datasets: [
                                label: "Penjualan",
                                fill: true,
                                lineTension: 0.3,
                                backgroundColor: gradient1,
                                borderColor: gradient1,
                                borderCapStyle: 'butt',
                                borderDash: [],
                                borderDashOffset: 0.0,
                                borderJoinStyle: 'miter',
                                borderWidth: 1,
                                pointBorderColor: gradient1,
                                pointBackgroundColor: "#fff",
                                pointBorderWidth: 1,
                                pointHoverRadius: 5,
                                pointHoverBackgroundColor: gradient1,
                                pointHoverBorderColor: "rgba(220,220,220,1)",
                                pointHoverBorderWidth: 2,
                                pointRadius: 1,
                                pointHitRadius: 10,
                                data: [graph],
                                spanGaps: false


the ajax response is look like this :


but it wont update the chart.

Washington Costa
Washington Costa Reply to 2018-02-14 07:54:47Z

Probally you're forgetting two things.

First: You need select the chart, something like this:
var ctx = document.getElementById("myChart").getContext('2d');

for use:

var myChart = new Chart(ctx, {
type: 'bar',
data: {//your code to build chart}

Second: myChart.update();


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.400624 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO