简体   繁体   中英

Plot the json array using jquery flot

var data =[ { label: "Foo", data: [ ["2012-09-01", 1], ["2012-10-01", -14], ["2012-11-01", 5] ] },
                { label: "Bar", data: [ ["2012-09-01", 13], ["2012-10-01", 11], ["2012-11-01", -7] ] }
    ];
    var options = {
        series: {
            lines: { show: true },
            points: { show: true }
        }
    };


<div id="placeholder"></div>
<script>
$.plot($('#placeholder'), data, options);
</script>

I am confused why the graph is not getting plotted with the data. Ignore my novice knowledge on flot. Can anyone give me an idea how i should be able to do it.

Are you sure flot can handle values formatted as strings? You should probably convert the strings to real dates or milliseconds...

You can use the moment.js library:

var data =[ { label: "Foo", data: [ [moment("2012-09-01","YYYY-MM-DD").toDate(), 1], ...

Flot does not automatically parse dates. If you want those to be used as-is then you should include the categories plugin . If you actually want to treat them as dates then you should convert them to dates as Nikos suggested and then take a look at the time plugin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM