Reputation: 199
I'm having some trouble creating a data chart with Google charts, I don't know why my chart is showing this way?
As you might see in the image the y value should be 2 but I'm getting a 3 or so. What can cause this problem?
This is my current code:
private DataTable GetData()
{
DataTable dt = new DataTable();
string cmd = "SELECT TotalShipped, TotalOnTime, TotalOnTime / TotalShipped * 100 AS LISC" +
" FROM (SELECT COUNT(*) AS TotalShipped, SUM(CASE LISC WHEN 100 THEN 1.0 ELSE 0.0 END) AS TotalOnTime" +
" FROM dbo.tbl_LISC) AS t";
SqlDataAdapter adp = new SqlDataAdapter(cmd, conn);
adp.Fill(dt);
return dt;
}
And:
private void BindChart()
{
DataTable dt = new DataTable();
try
{
dt = GetData();
str.Append(@"<script type=*text/javascript*> google.load( *visualization*, *1*, {packages:[*corechart*]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'TotalOnTime');
data.addColumn('number', 'LISC');
data.addRows(1);");
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
str.Append("data.setValue( " + i + "," + 1 + "," + "'" + dt.Rows[i]["LISC"].ToString() + "');");
str.Append("data.setValue(" + i + "," + 0 + "," + dt.Rows[i]["TotalOnTime"].ToString() + ") ;");
}
str.Append(" var chart = new google.visualization.BarChart(document.getElementById('chart_div'));");
str.Append(" chart.draw(data, {width: 1850, height: 500,bars: 'horizontal', title: 'Materiales',");
str.Append("hAxis: {title: 'LISC', titleTextStyle: {color: 'green'},viewWindow:{max:100,min:0}}");
str.Append("}); }");
str.Append("</script>");
lt.Text = str.ToString().Replace('*', '"');
}
catch
{
}
}
This is the query result:
Any help or comments on this is helpful. Thank you.
Upvotes: 1
Views: 560
Reputation: 1413
The y value is correct. Check your values on your Y-axis, they are divided in values of 3/4's.
Your graph is somewhere between 2.5 and 3.25, and a bit closer to 3.25 than 2.5, so a good guess is that it's around 2.
This is caused by googles function to automatically decide how many and to what values to attach your gridlines.
Check out the configuarion methods here, and jump down to vAxis.gridlines to see what you can vary to achieve what you're looking for.
Upvotes: 1