Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Plot a chart using Jqplot for a JSON object

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Plot a chart using Jqplot for a JSON object

    How to plot a jqplot chart for below object?
    $(document).ready(function() {
    var jsonobj={"x": {
    "y": "3",
    "z": {
    "name": "abcd",
    "hi": [
    {"a": "05/22/2014 12:33", "b": "80%"},
    {"a": "05/22/2014 12:34", "b": "70%"},
    {"a": "05/22/2014 12:35", "b": "60%"}
    ]
    }
    }
    }
    });


  2. #2
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Plot a chart using Jqplot for a JSON object

    Please wrap your code in the appropriate tags to make it easier to read.

    What specific problem(s) do you have?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Plot a chart using Jqplot for a JSON object

    As far as I can see this is Javascript and not Java code. Although the names are rather similar the languages are quite different.
    This is a java help forum, so your chances of finding help for your specific problem might not be too great.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Plot a chart using Jqplot for a JSON object

    Javascript != java. Thread moved

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Plot a chart using Jqplot for a JSON object

    This work is on JS. I have a JSON object. I have to plot a simple line chart using the below code that i have.
    $(document).ready(function() {
    var jsonoj={"report": {
    "count": "3",
    "oidObject": {
    "name": "CPU Utilization",
    "values": [
    {"timestamp": "05/22/2014 12:33", "value": "80%"},
    {"timestamp": "05/22/2014 12:34", "value": "70%"},
    {"timestamp": "05/22/2014 12:35", "value": "60%"},
    {"timestamp": "05/22/2014 12:36", "value": "50%"},
    {"timestamp": "05/22/2014 12:37", "value": "60%"},
    {"timestamp": "05/22/2014 12:38", "value": "70%"},
    {"timestamp": "05/22/2014 12:39", "value": "80%"}
    ]
    }
    }
    };
    var json = JSON.stringify(jsonobj);
    // alert(json);
    plot=$.jqplot('chart4', json,{
    dataRenderer: $.jqplot.ciParser,
    axes: {
    xaxis: {
    renderer:$.jqplot.DateAxisRenderer,
    // tickInterval: '1 day',
    tickOptions:{formatString:'%m/%d/%y'},
    min: '05/22/2014',
    max: '05/23/2014'
    }
    },
    });
    });


    and my html page contents are,

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>hi</title>
    <script type="text/javascript" src="./JSfiles/jquery.js"></script>
    <script type="text/javascript" src="./JSfiles/jquery.jqplot.js"></script>
    <script type="text/javascript" src="./JSfiles/jqplot.canvasTextRenderer.min.js"></script>
    <script type="text/javascript" src="./JSfiles/jqplot.categoryAxisRenderer.min.js"></script>
    <script type="text/javascript" src="./JSfiles/jqplot.canvasAxisTickRenderer.min.js"></script>
    <script type="text/javascript" src="./JSfiles/jqplot.ciParser.js"></script>
    <script type="text/javascript" src="./JSfiles/jqplot.dateAxisRenderer.min.js"></script>
    <script type="text/javascript" src="./JSfiles/json2.js"></script>

    <script type="text/javascript" src="./JSfiles/ChartusingJSON.js"></script>
    </head>
    <body>
    <div id="chart4" style="margin-top:20px; margin-left:20px; width:400px; height:300px;"></div>
    </body>
    </html>


    Thanks.

  6. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Plotting a chart from a JSON object using Jqplot

    JS works fine till array formation which has to be given to jqplot to plot simple line chart. But, jqplot is not working here. Alert(arr2) gives the exact structure to be given to jqplot. Dont know what went wrong. Help needed only on plotting the chart. Thanks in advance.
    $(document).ready(
    function() {
    var jsonobj = {
    "report" : {
    "count" : "3",
    "oidObject" : {
    "name" : "CPU Utilization",
    "values" : [ {
    "timestamp" : "05/22/2014 12:33",
    "value" : "80%"
    }, {
    "timestamp" : "05/22/2014 12:34",
    "value" : "70%"
    }, ]
    }
    }
    };
    alert(jsonobj.report.oidObject.values);
    var arr1 = [];
    alert(jsonobj.report.oidObject.values.length);
    $.each(jsonobj.report.oidObject.values, function(i, values) {
    arr1.push(("['" + values.timestamp + "',"
    + parseInt(values.value) + "]"));
    });
    // alert(arr1);
    var arr2 = [];
    arr2 = ('[' + arr1 + ']');
    // alert(arr2);
    plot = $.jqplot('chart4', [ arr2 ], {
    title : 'ex',
    axes : {
    xaxis : {
    renderer : $.jqplot.DateAxisRenderer,
    tickOptions : {
    formatString : '%#d'
    },
    tickInterval : '1 day',
    },
    yaxis : {
    tickOptions : {
    formatString : '%d'
    },
    }
    }
    });
    });

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Plot a chart using Jqplot for a JSON object

    Please don't start new threads on the subject...I have merged your new thread with the old. And please understand, this is a java forum, not a javascript forum. Your chances of getting help are much higher on a javascript (or jqplot) dedicated forum.

Similar Threads

  1. Exception while reading JSON object
    By swarna in forum Java Theory & Questions
    Replies: 4
    Last Post: February 21st, 2013, 12:33 AM
  2. Exception while reading JSON object
    By swarna in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 20th, 2013, 03:21 PM
  3. Replies: 0
    Last Post: January 30th, 2013, 04:41 AM
  4. consume the rest service by passing the json object
    By StarRocks in forum Object Oriented Programming
    Replies: 0
    Last Post: January 29th, 2013, 06:28 AM
  5. line plot Print statements
    By lf2killer in forum Java Theory & Questions
    Replies: 3
    Last Post: September 20th, 2012, 06:47 AM

Tags for this Thread