C3: Cartographie dynamique à l'aide d'un fichier JSON externe

Créé le 15 oct. 2016  ·  3Commentaires  ·  Source: c3js/c3

Je tiens à vous remercier d'avoir créé cette grande bibliothèque open source.
Je souhaite créer des graphiques dynamiques à l'aide d'un fichier JSON externe dans lequel le graphique analyse les données json chacune à la fois.
Mon code actuel :
var chart = c3.generate({ bindto: '#chart', size: { height: 240, width: 480 }, data: { url: 'static/data/trainp.json', mimeType: 'json', keys: { x: 'Series', value: ['Setting1'] }, type: 'line' }, subchart: { show: true } });

Exemple du graphique requis : https://jsfiddle.net/cy2owjva/

S'il vous plaît laissez-moi savoir quel changement je dois faire dans https://jsfiddle.net/cy2owjva/ .
Merci

Commentaire le plus utile

@AskSaikatSinha Essayez ceci
`
$(fonction () {

$.getJSON('./linejson.json', function (externaldata) {
var chart = c3.generate({
    title: {
        text:'External JSON loading via C3.js'
    },
    bindto: '#chart',
    data: {
       json: externaldata,
        type: 'area-spline',

    }
})

setInterval(function(){
    chart.flow({
        columns:
                [
                    ['data1',Math.round(Math.random()*200)]
                ],
        type:'area-spline'
    })
}, 1500)

});
})
`

et avoir votre fichier JSON externe comme ça

fichier linejson.json

{ "data1": [30, 20, 50, 40, 60, 50] }

Tous les 3 commentaires

@AskSaikatSinha Essayez ceci
`
$(fonction () {

$.getJSON('./linejson.json', function (externaldata) {
var chart = c3.generate({
    title: {
        text:'External JSON loading via C3.js'
    },
    bindto: '#chart',
    data: {
       json: externaldata,
        type: 'area-spline',

    }
})

setInterval(function(){
    chart.flow({
        columns:
                [
                    ['data1',Math.round(Math.random()*200)]
                ],
        type:'area-spline'
    })
}, 1500)

});
})
`

et avoir votre fichier JSON externe comme ça

fichier linejson.json

{ "data1": [30, 20, 50, 40, 60, 50] }

Je suis dans le même problème. Essayer d'animer un graphique avec un flux de données en temps réel.
essayé ceci :

var xhr = new XMLHttpRequest();
function reload(){
    //each call on this url changes the json
    xhr.open('GET', "http://127.0.0.1:5000/json/", true).send(); 
    chart.flow('http://127.0.0.1:5000/json/');
    chart.flush()
}

setInterval(reload, 500);

J'ai essayé de flux, de génération, de chargement et aucun de ceux-ci ne recharge le graphique sans avoir à recharger le navigateur.

Des conseils ?

@HawiCaesar Merci, votre code fonctionne.

Cette page vous a été utile?
0 / 5 - 0 notes

Questions connexes

kethomassen picture kethomassen  ·  3Commentaires

MarcusJT picture MarcusJT  ·  4Commentaires

patternboxtech picture patternboxtech  ·  4Commentaires

mwho picture mwho  ·  3Commentaires

laurentdebricon picture laurentdebricon  ·  3Commentaires