Starting the Line Chart from 92 until 100, not from 0 until 100?

9 views
Skip to first unread message

Mitra

unread,
Jan 3, 2008, 7:55:35 AM1/3/08
to Google Chart API
Hi, i love this chart api! It's great...
But i hav a little problem. I would like to generate a line chart with
21 data strings between 92 and 100. If i generate the chart, i can
change the labels to 92 until 100, but the line is drawed like 0-100.
So all my data strings are very on the top of the chart... is it
possible change the scale?

Here is my code:
http://chart.apis.google.com/chart?cht=lc&chs=220x110&chd=t:99.9,99.9,99.9,96.9,98.7,98.1,99.9,99.9,99.9,97.9,92.7,99.3,100.0,99.9,99.9,96.7,98.9,99.9,99.9,99.9,99.9&chxt=x,y&chxs=0,666666,7|1,666666,7&chxl=0:|1|2|6|7|8|9|12|13|14|15|16|19|20|21|22|23|26|27|28|29|30&chxp=1,92,93,94,95,96,97,98,99,100&chxr=1,92,100
Message has been deleted
Message has been deleted

Felipe Barone

unread,
Jan 3, 2008, 8:38:25 PM1/3/08
to Google Chart API
Hi Mitra,

i had this same issue yesterday: needed values from 0 to 50.000, so
the simple solution is to use a transformation on the values (such
that they would be inside the correct range for chart type) and then
plot the chart. Notice that (at least i think so) you cant change the
scale itself. Each chart type has its limitation for the max and
minimum value so, at least from my point of view here, you must adapt
the VALUES to the scale and this can be a bit trick indeed.

For your chart for example, lets suppose the values: 92,98,94,93,100.
Si we need to transform those values to the new y-axis scale, like
this:
Original axis: yi <= y <= yf, hences: 0 <= y <= 100

Custom axis:ti <= t <= tf, hences: 92 <= ty <= 100

now we define two variables (lets call them Deltas):
Dy = yf - yi, hences Dy = 100 - 0 = 100
and
Dt = ti - tf, hences Dt = 100 - 92 = 8

A third variable, which we gonna use to multiple the original values:
D = Dy / Dt, in this case:
D = 100 / 8 = 12.5

BUT, before we multiple the values, we need to change them by the
offset value of yi (in our case 92), which is our "zero" now.
SO, each value (V1, V2, V3, ..., Vn) in our data set is gonna be:
(Vn - yi) * D
in the example:
(92 - 92) * 12.5 = 0
(98 - 92) * 12.5 = 75
(94 - 92) * 12.5 = 50
and so on....
finally done this operation for all values we get the new data set:
0,75,25,12.5,100 which we gonna plot:

the chart URL would be:
http://chart.apis.google.com/chart?cht=lc&chs=400x400
&chd=t:0,75,25,12.5,100&chxt=x,y
&chxl=0:|1|2|6|7|8|9|12|13|14|15|16|19|20|21|22|23|26|27|28|29|30|1:|
92|93|94|95|96|97|98|99|100

this is a very common pitfall so i hope other people will use this as
well. notice that this transformation work for ANY VALUES in both X, Y
axis, makes no difference at all.

let me know if you still have question on the matter.

best regards,

Felipe

On Jan 3, 10:55 am, Mitra <renato.mi...@gmail.com> wrote:
> Hi, i love this chart api! It's great...
> But i hav a little problem. I would like to generate a line chart with
> 21 data strings between 92 and 100. If i generate the chart, i can
> change the labels to 92 until 100, but the line is drawed like 0-100.
> So all my data strings are very on the top of the chart... is it
> possible change the scale?
>
> Here is my code:http://chart.apis.google.com/chart?cht=lc&chs=220x110&chd=t:99.9,99.9...1,666666,7&chxl=0:|1|2|6|7|8|9|12|13|14|15|16|19|20|21|22|23|26|27|28|29|30&chxp=1,92,93,94,95,96,97,98,99,100&chxr=1,92,100

Mitra

unread,
Jan 4, 2008, 1:44:57 AM1/4/08
to Google Chart API
Hi Felipe

Thanks for this guide! That's exactly what i need.
Thank you!
Reply all
Reply to author
Forward
0 new messages