I am using the jquery plugin named flot to create some graphs for me in my spring mvc web application.
The example I am following to load the flot graph from an ajax call using json data can be found here http://www.flotcharts.org/flot/examples/ajax/.
This example shows that the json data loaded in the chart is in this format...
{
"label": "Japan",
"data": [[1999, -0.1], [2000, 2.9], [2001, 0.2], [2002, 0.3], [2003, 1.4], [2004, 2.7], [2005, 1.9], [2006, 2.0], [2007, 2.3], [2008, -0.7]]
}
Moving onto my data now, I already have a json controller that provides the data I want in the chart but it's in a different format...
[
{
"businessDate": "2015-02-10",
"thisYear": 20067,
"lastYear": 19252
},
{
"businessDate": "2015-02-11",
"thisYear": 21733,
"lastYear": 19365
},
{
"businessDate": "2015-02-12",
"thisYear": 28192,
"lastYear": 21982
}
]
My question is how do I get flot to read this type of json data strucutre? See below for what I am aiming for to appear in the graph.
Alternatively if that is not possible how can I transform my json returned into what appears below after getting the json back from the ajax call (using jquery)....
{
"label": "ThisYear",
"data": [[2015-02-10, 20067], [2015-02-11, 21733], [2015-02-12, 28192]]
}
{
"label": "LastYear",
"data": [[2014-02-10, 19252], [2014-02-11, 19365], [2014-02-12, 21982]]
}
thanks
[2015-02-10, 20067]is not valid javascript. You need to decide if you'll handle those dates as real times or as string categories.