Hi Ken,
You had some pretty fundamental issues in the code that you attached in
your initial post. The one that drew my eye is your .setColumns call. With
the way you're calling it, it seems like you expect it to set the type:
'boolean', and role: 'certainty' on all of the columns, which is not what
it does. .setColumns *changes* the columns of the chart to a subset (plus
calculated columns). So when you wrote .setColumns([2, 4, 6, 8]), that
means that those columns would be the only ones in the data table. You
actually don't need to use a DataView or the ready event at all. In fact,
here is an example of the chart you want: http://jsfiddle.net/stjxwsju/
I think one of the issues you may be seeing is that the jQuery CSV parser
doesn't detect boolean values, which is completely reasonable. You might
have to override it, and use a custom converter. Perhaps something like
this:
var arrayData = $.csv.toArrays(csvString, {onParseValue: function(value) {
if (value === 'false') {
return false;
} else if (value === 'true') {
return true;
} else {
return $.csv.hooks.castToScalar(value);
}
}});
Hopefully that will work. If you're still having issues, please post back
with your full HTML (and preferably an example CSV as well [in text, not a
screenshot]).
On Mon Dec 08 2014 at 9:36:33 AM Ken Burkhalter <[email protected]>
wrote:
> I think I figured out the issue here, and that was I needed to add a
> Listener to delay the attempts to modify column properties until the
> *visualization.**arrayToDataTable* effort was completed.
>
> I thus modified my code (yellow highlight) as follows but now am getting
> an All series on a given axis must be of the same data type× error that
> I can't seem to resolve.
>
> I think I'm getting close, but no cigar yet. :-(
>
> Help.
>
> <html>
> <head>
> <script src="https://www.google.com/jsapi"> </script>
> <script src="http://code.jquery.com/jquery-1.10.1.min.js"> </script>
> <script src="http://jquery-csv.googlecode.com/git/src/jquery.csv.js"
> ></script>
>
>
> <script>
> // Load the Visualization API from Google and set Listener
> google.load("visualization", "1", {packages:["corechart"]});
> google.setOnLoadCallback(drawChart);
>
>
> // this has to be a global function
> function drawChart() {
> // grab the CSV
> $.get("temps.csv", function(csvString) {
> // transform the CSV string into a 2-dimensional array
>
> var chartTbl = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.
> castToScalar});
> alert (chartTbl[0]+ '\n' + chartTbl[1]);
> //alert(chartTbl.join('\n'));
>
> // this new DataTable object holds all the data
>
> var data = new google.visualization.arrayToDataTable(chartTbl);
>
>
>
> // Define the 'certainty' columns
>
> google.visualization.events.addListener(data, 'ready', function(event) {
>
> data.setColumnProperty(2, 'role', 'certainty');
> data.setColumnProperty(4, 'role', 'certainty');
> data.setColumnProperty(6, 'role', 'certainty');
> data.setColumnProperty(8, 'role', 'certainty');
>
> data.setColumnProperty(8, 'type', 'boolean');
>
> data.setColumnProperty(10,'role', 'certainty');
> data.setColumnProperty(10,'type', 'boolean');
>
> });
>
>
>
> // set chart options
> var start = -20;
> var vTicks = [];
> while (start <= 100) {
> vTicks.push(start);
> start+=10;
> }
>
>
> var options = {
> fontSize: 8,
> legend: {position: 'right'},
> colors: ['green', 'blue', 'red', 'green', 'yellow', 'gray'],
> series: {
> 0: { lineDashStyle: [2, 2] }
> },
> hAxis: {
> title: 'Time',
> gridlines: {
> count: 25,
> },
> minorGridlines: {
> count: 3
> },
>
>
> },
> vAxis: {
> title: 'Temperature',
> gridlines: {
> count: 12,
> },
> minorGridlines: {
> count: 4
> },
> ticks: vTicks
> }
> };
> var chart = new google.visualization.LineChart(document.getElementById(
> 'chart_div'));
> chart.draw(data,options);
> });
> }
>
> </script>
> </head>
>
> <body>
> <div id="chart_div" style="width: 800px; height: 300px;"></div>
> </body>
> </html>
>
>
>
> --
> 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 [email protected].
> To post to this group, send email to
> [email protected].
> Visit this group at
> http://groups.google.com/group/google-visualization-api.
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.