ScrewzLuse
ScrewzLuse

Reputation: 1

Jquery Flot problem when loading JSON

Sorry for the noob question. I've read through a couple questions and am unable to solve my problem. I cannot seem to load the data.

I have the following json code output from a php script.

{label: "load",data:[[1283294013*1000, 2.03],[1283293998*1000, 2.04],[1283293983*1000, 2.06],[1283293968*1000, 1.99],[1283293953*1000, 1.98],[1283293937*1000, 1.98],[1283293922*1000, 1.97],[1283293907*1000, 1.97],[1283293892*1000, 1.96],[1283293877*1000, 1.95],[1283293862*1000, 2.03]]}

With the following options

  var options = {
    legend: {
      show: true,
      margin: 10,
      backgroundOpacity: 0.5
    },
    lines: { show: true },
    xaxis: {
      mode: "time",
      timeformat: "%H:%M"
    },
    yaxis: { min: 0, },
    grid: { hoverable: true }
  };

The actual script looks like the following

  var plotArea = $("#plotArea");
  plotArea.css("height", "450px");
  plotArea.css("width", "800px");

  $.getJSON("getStats.php", function(data) {
      alert(data);
      $.plot( plotArea , data, options );
    });

The alert doesn't load at all. With FireBug, I can see the data was returned but nothing happens.

When using the following instead, data passes. The alert runs and a graph shows up with nothing on the graph.

$.get("getStats.php", function(data) {
      alert(data);
      $.plot( plotArea , data, options );
    });

I can get this to run when just including the getStats.php in the code but that's not really what I'm shooting for.

Upvotes: 0

Views: 687

Answers (2)

Hogan
Hogan

Reputation: 70538

also I would expect the last 3 characters to look like ]]} not ]},

Upvotes: 0

Vadim Shender
Vadim Shender

Reputation: 6723

JSON data mustn't contain math operations (multiplications in your case). Send already calculated values instead of expressions.

Upvotes: 1

Related Questions