views:

32

answers:

1

I'm trying to make an XYLine with the Google Chart API via the not-so-well-documented GChartWrapper libraries.

Here's a portion of the code that is supposed to generate the graph:

data = []
traffic_max = 0
date_minmax = []

#I have a number of timestamped readings in two series
for site in sites:
  site_data = get_datapoints_for(site)

  date_values = [datetime_to_unix(item.timestamp) for item in site_data]
  date_minmax = minmax(date_minmax + date_values) #get min and max values for
                                                  #scaling
  traffic_values = [item.traffic for item in site_data]
  traffic_max = max(traffic_max, *traffic_values) #just get maximum for readings

  #build graph
  data.append(date_values)
  data.append(traffic_values)

#add leeway to axes
date_minmax[0] -= 500
date_minmax[1] += 500
traffic_max /= 0.9

#build graph
chart = LineXY(data)
chart.legend(*sites)
chart.color("green", "red")
chart.size(600,400)
chart.scale(date_minmax[0], date_minmax[1], 0, traffic_max)
chart.axes.type("xy")
chart.axes.range(0, *date_minmax)
chart.axes.range(1, 0, traffic_max)

chart_url = chart.url

However, this is what I get:

link text

Question: What happened to the red series?


For your convenience, here is data after some pretty print love:

[[1286116241.448437, 1286118544.4077079, 1286119431.18503, 1286121011.5838161],
 [6710.9899999999998,
  6716.2799999999997,
  6641.8900000000003,
  6644.9499999999998],
 [1286116241.979831,
  1286118545.0123601,
  1286119431.9650409,
  1286121012.1839011],
 [38323.860000000001,
  38326.620000000003,
  38327.660000000003,
  38329.610000000001]]

Here is the list of parameters generated by the wrapper, also after some pretty print love:

chco=008000,FF0000
chd=t:1286116241.0,1286118544.0,1286119431.0,1286121011.0
    6711.0,6716.3,6641.9,6644.9
    1286116241.0,1286118545.0,1286119431.0,1286121012.0
    38323.9,38326.6,38327.7,38329.6
chdl=gaming.stackexchange.com
    serverfault.com
chds=1286115741.0,1286121512.0,0,42588.4555556
chs=600x400
cht=lxy
chxr=0,1286115741.0,1286121512.0
    1,0,42588.4555556
chxt=x,y
cht=lxy
chxr=0,1286116241.45,1286121012.18
    1,0,42588.4555556
chxt=x,y
A: 

The problem was here:

chart.scale(date_minmax[0], date_minmax[1], 0, traffic_max)

The Google API allows you to define a different scale per each series. Thus, you need to specify the scaling for each series, whereas the above only affected the first series.

Changing that line to:

chart.scale(*[date_minmax[0], date_minmax[1], 0, traffic_max]*len(sites))

...forces all series to the same scaling.

badp