Using Webmatrix i got an .cshtml page to produce a json
@{
var db = Database.Open("AppCCentro");
var data = @"SELECT ESTADO, COUNT(*) CNT FROM graficos WHERE ESTADO IS NOT
NULL GROUP BY ESTADO";
var resultadoSql = db.Query(data);
Json.Write(resultadoSql, Response.Output);
Response.ContentType = "application/json";
}
This produces this json
[{"ESTADO":"ABERTO","CNT":63},{"ESTADO":"ASSOCIADO A AVARIA
PAI","CNT":9},{"ESTADO":"AVARIA PAI COM EM EXECUÇÃO","CNT":3},{"ESTADO":"AVARIA
PAI EM DESPISTE","CNT":3},{"ESTADO":"CANCELADO","CNT":3},{"ESTADO":"EM
DESPISTE","CNT":18},{"ESTADO":"EM
EXECUÇÃO","CNT":27},{"ESTADO":"FECHADO","CNT":189},{"ESTADO":"RESOLVIDO","CNT":51}]
Then on other page i try to load a chart with this
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "teste.cshtml",
dataType:"json",
async: false
}).responseText;
function jsonToTable(json, order) {
var headers = [];
var data = [headers];
for (var i = 0; i < json.length; i++) {
var row = [];
for (var j = 0; j < order.length; j++) {
if (headers.length <= j) {
headers.push(order[j]);
}
row.push(json[i][order[j]]);
}
data.push(row);
}
return google.visualization.arrayToDataTable(data);
}
var data = jsonToTable(jsonData, ['ESTADO', 'CNT']);
// Instantiate and draw our chart, passing in some options.
var chart = new
google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 800, height: 600});
}
</script>
But it gives the following error
Data column(s) for axis #0 cannot be of type string×
Can someone help ?
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-chart-api.
For more options, visit https://groups.google.com/d/optout.