epochjs / epoch

A general purpose, real-time visualization library.
http://epochjs.github.io/epoch
MIT License
4.97k stars 278 forks source link

Question: How to use an Ajax datasource (JSON object) #141

Closed webmutation closed 10 years ago

webmutation commented 10 years ago

Hi guys, started using this library today... however I am having some issues understanding how to load AJAX data into the charts... I am trying to do this but it does not seem to work

    $.getJSON("/realtime-count", function( barChartData ) {
        activitychart.push(barChartData);
    })

where barChartData is something like: [{"label":"TwitterActivity","values":[{"time":1415112900,"y":17},{"time":1415112960,"y":13},{"time":1415113020,"y":53},{"time":1415113080,"y":81},{"time":1415113140,"y":10},{"time":1415113200,"y":16},{"time":1415113260,"y":15},{"time":1415113320,"y":7},{"time":1415113380,"y":8},{"time":1415113440,"y":12},{"time":1415113500,"y":4},{"time":1415113560,"y":5},{"time":1415113620,"y":3},{"time":1415113680,"y":6},{"time":1415113740,"y":3},{"time":1415113800,"y":11},{"time":1415113860,"y":3},{"time":1415113920,"y":6},{"time":1415113980,"y":9},{"time":1415114040,"y":8},{"time":1415114100,"y":7},{"time":1415114160,"y":15},{"time":1415114220,"y":5},{"time":1415114280,"y":8},{"time":1415114340,"y":7},{"time":1415114400,"y":9},{"time":1415114460,"y":7},{"time":1415114520,"y":11},{"time":1415114580,"y":7},{"time":1415114640,"y":4}]}]

this renders correctly the first time it is initialized although I have to resort to

$.getJSON("/realtime-count", function( barChartData ) {
    activitychart = $('#barChart').epoch({
                        type: 'time.bar',
                        axes: ['right', 'bottom', 'left'],
                        data:  barChartData
                    });
})

So I am pretty sure that I am probably not doing something right, I could not find any examples consuming JSON, looking at the code.

I am not sure how the push method is supposed to work.

webmutation commented 10 years ago

Ok, Apparently this does not work as I though, you just push one new not a stream with updated values. More documentation would be nice.