1
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.

2 Answers 2

2

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], ...
Sign up to request clarification or add additional context in comments.

1 Comment

Instead of moment.js, I am converting it the date to time in milliseconds and used xaxis: {mode: "time", timeformat: "%b-%Y"}. It worked perfectly fine
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.