Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6127151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:28:12+00:00 2026-05-23T16:28:12+00:00

I would like to use jqPlot usinge data from server side coming in JSON,

  • 0

I would like to use jqPlot usinge data from server side coming in JSON, like described in this example: http://www.jqplot.com/tests/data-renderers.php

My code is nearly the same like the example:

function myGraph(jsonurl) {

  var ajaxDataRenderer = function(url, plot, options) {
    var ret = null;
    $.ajax({
      // have to use synchronous here, else the function
      // will return before the data is fetched
      async: false,
      url: url,
      dataType:"json",
      success: function(data) {
        ret=data;
        console.warn(data);
      }
    });
    return ret;
  };



var plot1 = $.jqplot('chartdiv', jsonurl, {
      title: 'myTitle',
      dataRenderer: ajaxDataRenderer,
      dataRendererOptions: {  unusedOptionalUrl: jsonurl    },
      series: [{
          label: 'myLabel',
          neighborThreshold: -1
      }],
      axes: {
          xaxis: {
              renderer: $.jqplot.DateAxisRenderer,
            //  min:'August 1, 2010 16:00:00',
              tickInterval: '2 months',
              tickOptions:{formatString:'%Y-%m-%d.%H:%M:%S'}
          },
          yaxis: {
              tickOptions:{formatString:'$%.2f'}
          }
      },
  });

On server side i’m using PHP (and Yii). The webpage returns an array, which is encoded to JSON by using CJSON::encode($resultArray); (this Yii function passed trough to the PHP JSON encode function).
The Results from the PHP script lookes like that:

{"2011-04-25 14:46:40":2,"2011-04-26 14:46:40":3,"2011-04-27 14:46:40":5}

The Ajax request on client side resolved something like this (output from console.info(); )

Object { 2011-04-25 14:46:40=2,  2011-04-26 14:46:40=3, ...}

Probably, jqPlot expect the following format:

[[["2011-04-25 14:46:40":0],["2011-04-26 14:46:40",3],["2011-04-27 14:46:40",0]]]

All the time i get the error uncaught exception: [object Object]
What is wrong?
Is there a way to convert the object for to the typical array form?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:28:13+00:00Added an answer on May 23, 2026 at 4:28 pm

    I have something like this . I had 2 arrays for values,labels .You should construct string as below from arrays .

            $size = count($labels);
    
            for ($i = 0; $i < $size; $i++) {
                $result = $result . "['" . $labels[$i] . "'," . $values[$i] . "]";
                if($i != $size -1 ){
                    $result = $result . ",";
                }
            }
    

    OR if you dont have 2 arrays and just have this string {“2011-04-25 14:46:40″:2,”2011-04-26 14:46:40″:3,”2011-04-27 14:46:40”:5} you can replace { with [ , } with ] and , with ],[ . A dirty but quick solution .

    After above code you might need to append ‘[‘ and ‘]’ on both sides and return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to use the return of: http://maps.google.de/maps/suggest?q=ham&cp=1&hl=de&gl=de&v=2&json=b as a JSON object in a
I am using AdoNetAppender (SQL server) in my asp.net application and would like use
I would like to use client-side Javascript to perform a DNS lookup (hostname to
Designing my RESTful API, I would like use following URI http://[HOST]/[PLANET]/[LAT];[LONG] e.g. http://myserver/earth/50.2;29.1 What
I would like use data annotations to handle validation in my Silverlight app. The
I currently have some large strings that I would like use as test data
I would like to use this C function in C#: typedef void (*WRITE_CALLBACK)(int hMountEnv,
I would like use from Spring.NET Aspect library Logging aspect together with log4Net. I
I would like use .appendTo() on different elements determined by a function. For example,
I would like to use a language that I am familiar with - Java,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.