First attempt was to use php to query the DB format all my data in a way that Google wanted and then spit out the html into a div, this worked but was an extra step that was unnecessary.
For this example we'll go ahead and say I have a table of cities and their high temperatures for a given day in the last week, this will be a very simple table with 3 columns consisting of Timestamp, City, Temp. (In reality my table structure was a little more complicated, but for this example, a simple table called TempData should suffice).
The following stored procedure will get all the values needed from our database and return a varchar that consists of the html needed to display the graph, we can then put that value into a div and the graph will be displayed.
USE [DATABASENAME]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_google_temperature_trends]
AS
DECLARE
@Timestamp varchar(50),
@Year varchar(50),
@Month varchar(50),
@Day varchar(50),
@Hour varchar(50),
@Min varchar(50),
@City varchar(50),
@Temp varchar(50),
@avgTemp varchar(50),
@t int,
@html varchar(max),
@hideCityHtml varchar(max)
/* First We'll print out the top of the container info for the goolge annotated timeline graph, for google api info see:
http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html
*/
SET @html = '
' + @hideCityHtml +'
'
Hi Jim, can you post the web page that displays the graph too?
ReplyDeleteThanks