Line chart problem Type mismatch

4,334 views
Skip to first unread message

pantonis

unread,
Dec 10, 2011, 8:49:06 AM12/10/11
to Google Visualization API
Hi,

I'm trying to create a Line chart and I get the following error:

Type mismatch. Value 364390 does not match type number in column index
0
[Break On This Error] function Mq(a,b,c){if(c!=k){var a=a[Qb...ch type
"+a+" in column index "+b))}}

I'm populating the datasource with typeof int. Do you know what's
causing this error?
Below is my code

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Amount');
data.addRows(datasource);

var options = {
width: 800, height: 480,
title: 'Top sales'
};

var chart = new
google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}

William Espindola

unread,
Dec 10, 2011, 3:29:40 PM12/10/11
to Google Visualization API
I think this error is happening because you are not loading the data.
Tell me, this Will be static data or you will bring an outside source?

Antonis Panagi

unread,
Dec 10, 2011, 6:13:13 PM12/10/11
to google-visua...@googlegroups.com
I'm loading the data from outside (db). I do not think that the problem is not loading the data because I checked my datasource and it has about 200 records in it. If you see also the error message I get "Value 364390" it means that there is some data. The problem is parsing of this data. I checked the type before adding it to the datasource and is type of decimal.

Thanks,

AP


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


William Espindola

unread,
Dec 10, 2011, 7:01:12 PM12/10/11
to Google Visualization API
What I am talking about is the way that you are seeking this data.
Take a look here in this documentation:
http://code.google.com/apis/chart/interactive/docs/php_example.html
Any questions just ask

On Dec 10, 9:13 pm, Antonis Panagi <antonis...@gmail.com> wrote:
> I'm loading the data from outside (db). I do not think that the problem is
> not loading the data because I checked my datasource and it has about 200
> records in it. If you see also the error message I get "Value 364390" it
> means that there is some data. The problem is parsing of this data. I
> checked the type before adding it to the datasource and is type of decimal.
>
> Thanks,
>
> AP
>

Roni Biran

unread,
Dec 11, 2011, 2:39:04 AM12/11/11
to google-visua...@googlegroups.com
Hi,

The datasource (as you pointed) should be in your case a JSON format datatable object, as in the following format:

var data = new google.visualization.DataTable(
     {
       cols: [{id: 'task', label: 'Task', type: 'string'},
                {id: 'hours', label: 'Hours per Day', type: 'number'}],
       rows: [{c:[{v: 'Work'}, {v: 11}]},
              {c:[{v: 'Eat'}, {v: 2}]},
              {c:[{v: 'Commute'}, {v: 2}]},
              {c:[{v: 'Watch TV'}, {v:2}]},
              {c:[{v: 'Sleep'}, {v:7, f:'7.000'}]}
             ]
     },
   0.6
)

so unless your data looks like this, your chart will not be shown.

Antonis Panagi

unread,
Dec 11, 2011, 4:42:50 AM12/11/11
to google-visua...@googlegroups.com
Roni thanks for your reply.
I'm using the MVC3 Razor syntax.

var datasource = [];

foreach(var item in Model)
{
  <text>
        datasource.push(['@item.TotalForMonth'])
  </text>
}


where @item.TotalForMonth is integer type

I have used the same code for pie chart and pie chart works.
Thanks

Roni Biran

unread,
Dec 11, 2011, 4:47:29 AM12/11/11
to google-visua...@googlegroups.com
So if all work fine I'm pleased...

Antonis Panagi

unread,
Dec 11, 2011, 5:07:04 AM12/11/11
to google-visua...@googlegroups.com
hehe.

The pie chart works. The line chart is not working

Roni Biran

unread,
Dec 11, 2011, 5:11:11 AM12/11/11
to google-visua...@googlegroups.com
The datasource needs to be the same. Are you rendering different datatable for the LineChart?

Antonis Panagi

unread,
Dec 11, 2011, 6:34:48 AM12/11/11
to google-visua...@googlegroups.com
I'm using exactly the same datasource.

pantonis

unread,
Dec 12, 2011, 4:01:18 AM12/12/11
to Google Visualization API
I found the issue. While building the datasource I enclosed the items
in single quotes which denote string whereas I shouldn't since my
column was type of number.

Thanks

On Dec 11, 1:34 pm, Antonis Panagi <antonis...@gmail.com> wrote:
> I'm using exactly the same datasource.
>
>
>
>
>
>
>
> On Sun, Dec 11, 2011 at 12:11 PM, Roni Biran <roni.bi...@gmail.com> wrote:
> > The datasource needs to be the same. Are you rendering different datatable
> > for the LineChart?
>

> > On Sun, Dec 11, 2011 at 12:07 PM, Antonis Panagi <antonis...@gmail.com>wrote:
>
> >> hehe.
>
> >> The pie chart works. The line chart is not working
>

> >> On Sun, Dec 11, 2011 at 11:47 AM, Roni Biran <roni.bi...@gmail.com>wrote:
>
> >>> So if all work fine I'm pleased...
>

> >>> On Sun, Dec 11, 2011 at 11:42 AM, Antonis Panagi <antonis...@gmail.com>wrote:
>
> >>>> Roni thanks for your reply.
> >>>> I'm using the MVC3 Razor syntax.
>
> >>>> var datasource = [];
>
> >>>> foreach(var item in Model)
> >>>> {
> >>>>   <text>

> >>>>         datasource.push(['...@item.TotalForMonth'])


> >>>>   </text>
> >>>> }
>
> >>>> where @item.TotalForMonth is integer type
>
> >>>> I have used the same code for pie chart and pie chart works.
> >>>> Thanks
>

Reply all
Reply to author
Forward
0 new messages