function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Date', 'Michelle 800m'],
['3/16', 163.84],
['4/13', 161.69],
['4/20', 162],
['5/4', 154.22],
['6/1', 155.46],
['6/8', 153],
['6/15', 151.22],
['6/22', 156.45],
['6/29', 153.45],
['7/31', 153.95]
]);
// Create and draw the visualization.
new google.visualization.LineChart(document.getElementById('visualization')).
draw(data, {curveType: "none",
width: 500, height: 250,
vAxis: {minValue: 140}}
);
}
--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.
private void RenderGraphs(List<BLL.Athlete> athletes)
{
StringBuilder script = new StringBuilder();
StringBuilder scriptData = new StringBuilder();
StringBuilder scriptViews = new StringBuilder();
StringBuilder scriptViz = new StringBuilder();
script.Append("<script type='text/javascript' src='https://www.google.com/jsapi'></script>\n");
script.Append("<script type='text/javascript' src='http://momentjs.com/downloads/moment-with-langs.js'></script>\n");
script.Append("<script type='text/javascript'>\n");
script.Append("\t");
script.Append("google.load('visualization', '1.1', {packages: ['corechart']});\n");
script.Append("\t");
script.Append("google.setOnLoadCallback(drawVisualization);\n\n");
script.Append("\tfunction drawVisualization() {\n");
script.Append("\t\t");
script.Append("function getTooltip(dataTable, rowNum) {\n");
script.Append("\t\t\t");
script.Append("var min = Math.floor(dataTable.getValue(rowNum, 1)[2]/60);\n");
script.Append("\t\t\t");
script.Append("var sec = dataTable.getValue(rowNum, 1)[2] - (min * 60);\n");
script.Append("\t\t\t");
script.Append("var ms = dataTable.getValue(rowNum, 1)[3];\n");
script.Append("\t\t\t");
script.Append("var newtime = new moment([1900, 1, 1, 0, min, sec, ms]);\n");
script.Append("\t\t\t");
script.Append("return newtime.format('m:ss.SS');\n");
script.Append("\t\t}\n\n");
StringBuilder divHTML = new StringBuilder();
int counter = 0;
foreach (BLL.Athlete athlete in athletes)
{
if (athlete.History != null && athlete.History.Count > 1)
{
counter++; // Increment athlete counter
divHTML.Append("<div id='divGraph" + counter.ToString() + "' />");
scriptData.Append("\t\tvar data" + counter.ToString() + " = google.visualization.arrayToDataTable([\n");
scriptData.Append("\t\t\t['Date', '" + athlete.FullName + "'],");
// Build array of data points
StringBuilder dataPoints = new StringBuilder();
double floor = 999999;
foreach (IPerformance p in athlete.History)
{
string shortDate = String.Format("{0:M/d}", p.PerformanceDate);
if (dataPoints.Length > 0)
dataPoints.Append(",");
double secs = Math.Truncate(p.ResultValue);
int ms = Convert.ToInt32((p.ResultValue - secs) * 1000);
dataPoints.Append("\n\t\t\t['" + shortDate + "', [0, 0, " + secs.ToString() + ", " + ms.ToString() + "]]");
if (p.ResultValue < floor)
floor = p.ResultValue;
}
scriptData.Append(dataPoints.ToString());
scriptData.Append("\n\t\t]);\n\n");
scriptViews.Append("\t\t");
scriptViews.Append("var view" + counter.ToString() + " = new google.visualization.DataView(data" + counter.ToString() + ");\n");
scriptViews.Append("\t\t");
scriptViews.Append("view" + counter.ToString() + ".setColumns([0, 1, {\n");
scriptViews.Append("\t\t\t");
scriptViews.Append("calc: getTooltip,\n");
scriptViews.Append("\t\t\t");
scriptViews.Append("type: 'string',\n");
scriptViews.Append("\t\t\t");
scriptViews.Append("role: 'tooltip'\n");
scriptViews.Append("\t\t}]);\n\n");
string minValue = (floor * .9).ToString("N0");
string hAxis = "hAxis: { title: 'Date' }";
string vAxis = "vAxis: { title: 'Time', minValue: " + minValue + ", format: 'm:ss'}";
scriptViz.Append("\t\t");
scriptViz.Append("new google.visualization.LineChart(document.getElementById('divGraph" + counter.ToString() + "')).draw(view" + counter.ToString() + ", {curveType: 'none', width: 600, height: 300, " + hAxis + ", " + vAxis + "});\n");
}
}
// Write out data arrays
script.Append(scriptData.ToString());
// Write out data views
script.Append(scriptViews.ToString());
// Write out calls to LineChart method
script.Append(scriptViz.ToString());
// Create new div for each of the graphs
script.Append("divGraphContainer.innerHTML=\"" + divHTML.ToString() + "\";\n");
script.Append("\t}\n");
script.Append("</script>");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GoogleChartsScript", script.ToString(), false);
}
script.Append("divGraphContainer.innerHTML=\"" + divHTML.ToString() + "\";\n");
scriptViz.Append("new google.visualization.LineChart(document.getElementById('divGraph" + counter.ToString() + "')).draw(view" + counter.ToString() + ", {curveType: 'none', width: 600, height: 300, " + hAxis + ", " + vAxis + "});\n");