The problem is here:
'filterColumnLabel': columnNames.split(',')[2],
Since you are not setting a label for the 3rd column, filterColumnLabel
gets set to an empty string, which the API does not like. Either set a
column label for the 3rd column, or use filterColumnIndex instead:
filterColumnIndex: 2,
Incidentally, you will have a problem in IE with the trailing comma in your
data array:
[{"ColumnName":"ADAGI","Value":59,"Type":"CVR"},{"ColumnName":"AXIUS","Value":32,"Type":"CVR"},{"ColumnName":"BACCH","Value":75,"Type":"CVR"}
,] <-- this comma
IE with throw a fit to rival a petulant 2-year-old child at the sight of
such a comma.
On Tuesday, February 25, 2014 11:29:19 AM UTC-5, Missy wrote:
>
> Thank you for your response back.
>
> Here is my sample of dataValues result:
>
> <script
> type="text/javascript">google.load('visualization','1.0',{'packages':['corechart','controls']});google.setOnLoadCallback(function(){drawVisualization([{"ColumnName":"ADAGI","Value":59,"Type":"CVR"},{"ColumnName":"AXIUS","Value":32,"Type":"CVR"},{"ColumnName":"BACCH","Value":75,"Type":"CVR"},],'Text
>
> Example','Name,type,');});</script><script type='text/javascript'>new
> Sys.WebForms.Menu({ element: 'NavigationMenu', disappearAfter: 500,
> orientation: 'horizontal', tabIndex: 0, disabled: false });</script>
> </form>
>
>
>
>
> On Tuesday, February 25, 2014 4:17:39 PM UTC, asgallant wrote:
>>
>> Can you post an example of what your server-side code outputs
>> for dataValues?
>>
>> On Tuesday, February 25, 2014 10:50:43 AM UTC-5, Missy wrote:
>>>
>>> I am getting the "failed to draw" error on the client-end using the
>>> following code below:
>>>
>>> <script type="text/javascript">
>>> function drawVisualization(dataValues, chartTitle, columnNames,
>>> categoryCaption) {
>>> if (dataValues.length < 1)
>>> return;
>>>
>>> var data = new google.visualization.DataTable();
>>> data.addColumn('string', columnNames.split(',')[0]);
>>> data.addColumn('number', columnNames.split(',')[1]);
>>> data.addColumn('string', columnNames.split(',')[2]);
>>>
>>>
>>> for (var i = 0; i < dataValues.length; i++) {
>>> data.addRow([dataValues[i].ColumnName,
>>> dataValues[i].Value, dataValues[i].Type]);
>>> }
>>>
>>> // Define a category picker control for the Gender column
>>> var categoryPicker = new
>>> google.visualization.ControlWrapper({
>>> 'controlType': 'CategoryFilter',
>>> 'containerId': 'CategoryPickerContainer',
>>> 'options': {
>>> 'filterColumnLabel': columnNames.split(',')[2],
>>> 'ui': {
>>> 'labelStacking': 'horizontal',
>>> 'allowTyping': false,
>>> 'allowMultiple': false,
>>> 'caption': categoryCaption,
>>> 'label': columnNames.split(',')[2]
>>> }
>>> }
>>> });
>>>
>>> // Define a Pie chart
>>> var pie = new google.visualization.ChartWrapper({
>>> 'chartType': 'LineChart',
>>> 'containerId': 'PieChartContainer',
>>> 'options': {
>>> 'width': 950,
>>> 'height': 450,
>>> 'legend': 'right',
>>> 'title': chartTitle,
>>> 'chartArea': { 'left': 100, 'top': 100, 'right': 0,
>>> 'bottom': 100 },
>>> 'pieSliceText': 'label',
>>> 'tooltip': { 'text': 'percentage' }
>>> },
>>> 'view': { 'columns': [0, 1] }
>>> });
>>>
>>> new
>>> google.visualization.Dashboard(document.getElementById('PieChartExample')).bind([categoryPicker],[pie]).draw(data);
>>> }
>>>
>>>
>>> </script>
>>> <div id="PieChartExample">
>>> <table>
>>> <tr style='vertical-align: top'>
>>> <td>
>>> <div id="CategoryPickerContainer"></div>
>>> <div id="control1"></div>
>>> <div id="control2"></div>
>>> </td>
>>> </tr>
>>> <tr>
>>> <td >
>>> <div style="float: left;"
>>> id="PieChartContainer"></div>
>>> </td>
>>>
>>> </tr>
>>> </table>
>>> </div>
>>>
>>> Code behind - default.aspx.cs
>>> protected void Page_Load(object sender, EventArgs e)
>>> {
>>> if (!IsPostBack)
>>> {
>>>
>>> JavaScriptSerializer jss = new JavaScriptSerializer();
>>> ClientScript.RegisterStartupScript(this.GetType(),
>>> "TestInitPageScript",
>>> //string.Format("<script
>>> type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
>>> string.Format("<script
>>> type=\"text/javascript\">google.load('visualization','1.0',{{'packages':['corechart','controls']}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}');}});</script>",
>>> jss.Serialize(GetData()),
>>> "Text Example",
>>> "Name,type,"));
>>>
>>>
>>> }
>>> }
>>>
>>> [WebMethod]
>>> public static List<Data> GetData()
>>> {
>>> SqlConnection conn = new SqlConnection("######");
>>>
>>>
>>> DataSet ds = new DataSet();
>>> DataTable dt = new DataTable();
>>> conn.Open();
>>> string cmdstr = "select top 100 Name, [Decimal price],Cover from
>>> [dbo].[database]";
>>> SqlCommand cmd = new SqlCommand(cmdstr, conn);
>>> SqlDataAdapter adp = new SqlDataAdapter(cmd);
>>> adp.Fill(ds);
>>> dt = ds.Tables[0];
>>> List<Data> dataList = new List<Data>();
>>> string cat="";
>>> float val=0;
>>> string typ = "";
>>>
>>> foreach (DataRow dr in dt.Rows)
>>> {
>>> try
>>> {
>>> cat = dr[0].ToString();
>>>
>>> val = Convert.ToInt32(dr[1]);
>>>
>>> typ = dr[2].ToString();
>>>
>>> }
>>> catch
>>> {
>>> }
>>> dataList.Add(new Data(cat, val, typ));
>>> }
>>> return dataList;
>>> }
>>>
>>> Any help would be very much appreciated. Thanks
>>>
>>
--
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/groups/opt_out.