views:

252

answers:

1

I'm pulling my hair out on this problem.

I would like to show a very simple vertical bar graph which will represent the amount of sales during a week. So the data it would be fed is:

Sunday: 200
Monday : 50
Tue: 500
Wed: 300
Thu: 145
Fri: 0
Sat: 976

This would only be for a single given week, and I want the graph to show the sales data between the days to compare them and see which day had the most number of sales, etc.

Then I'll want two other similar graphs, one for monthly sales, e.g

January: 2000
Feb: 1490
..
December: 4553

And an yearly graph e.g:

2006: 20000
...
2009 30000

Again the comparison will be just between the 7 days of the week, 12 months of the year, or 4-5 years.

I need a url which can be used to create these graphs, where I can just hook in my own data and the rest of the stuff would work by itself. Out of the chart types I'd like to use 'Vertical bar graph' (code bvs).

One thing which can be a problem is the 'encoding' of the graphs, google charts seems to want you to give it an encoding which means a range between 0-500 or 0-6950, but I have no way of knowing which encoding the sales amounts would fall into, they could either be very little sales or very much.

+1  A: 

Here's the day of the week URL:

http://chart.apis.google.com/chart?cht=bvs&chs=500x300&chd=t:200,50,300,145,0,976&chds=0,1000&chm=tMonday,000000,0,0,10|tTuesday,000000,0,1,10|tWednesday,000000,0,2,10|tThursday,000000,0,3,10|tFriday,000000,0,4,10|tSaturday,000000,0,5,10

cht is the chart type, bhs is the basic bar graph

chs is the chart size, in widthxheight

chd is your data, and I'm not using the encoding that Google allows to shorten URLs.

chds is a data scaling (optional), in which I'm saying that the minimum value is 0 and the max value is 1000.

chm is your labels. Each label is separated by a '|' symbol. Each label is comples of a t (type text), followed by the label, then command and a color (RGB hex value, RRGGBB), then which data series to label (you only have 1, so using 0), then the data point to label (starting with 0 for the 1st one), then the point size of the font to use. There's one more omitted value that is "when to draw the label", since I left it out, it's drawn after bars but before other labels.

See the data point labels documentation, the chart basics documentation, and the data scaling documentation for more info.

UPDATE: Changed chart type from bhs to bvs after re-reading OP. UPDATE 2: Updated white space for readability

Tony Miller
Hey, thanks a lot for this. Currently this is showing the day names only, Is there a way to add labels showing the amount of sales to this as well (Such as underneath the bars)?
Click Upvote
1 more thing, can I change the color of the bars from yellow to another color like #4D89F9 , if so how?
Click Upvote
Bar color is chco, you'd say chco=4D89F9 in the URL
Tony Miller