4

I've a JSON data like this

{
    "srno": 1234567890,
    "datetime": "MM-dd-yyyy HH:mm",
    "meters": [
    {
        "mid": 63,
        "phase":1,
        "v": 1234,
        "c": 5678,
        "kw": 2348,
        "kwh": 2342,
        "okda" : 1,
        "poca" : 1
    },
    {
        "mid": 62,
        "phase":2,
        "v": 1234,
        "c": 5678,
        "kw": 2348,
        "kwh": 2342,
        "okda" : 1,
        "poca" : 3
    }
  ]
}

All i want is to plot this data on my webpage. Please Help me out. The Jquery for the same can be inferred from this link

https://jsfiddle.net/93ttkjr4/

i want this data to be populated on my web page.

2
  • what plotting library are you using? Commented Feb 2, 2016 at 7:15
  • Hi Madalin, I'm using flot.js as my plotting library Commented Feb 2, 2016 at 7:18

1 Answer 1

1

You have to change your data into the right format for Flot (which is arrays of arrays of arrays) with something like this (example_data is the JSON from your question):

var bar_data = [];
for (var i = 0; i < example_data.meters.length; i++){
    var meter = example_data.meters[i];
    var temp = { data: [], bars: { order: i }};
    for (item in meter){
        temp.data.push([item, meter[item]]);    
    }
    bar_data.push(temp);
}

See this fiddle for a full example using the Side-by-side Improved plugin for the bars.

Sign up to request clarification or add additional context in comments.

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.