DataView calculated column pattern

1,549 views
Skip to first unread message

laurenty

unread,
Jul 8, 2010, 7:26:50 PM7/8/10
to Google Visualization API
Is it possible to specify the pattern of a calculated column in
DataView without to use google.visualization.PatternFormat afterwards?

Thanks

Laurent

ChartMan

unread,
Jul 9, 2010, 6:24:09 AM7/9/10
to google-visua...@googlegroups.com
Can you please give an example of a data input and the required output.

Thanks
ChartMan 


--
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.


laurenty

unread,
Jul 9, 2010, 4:38:23 PM7/9/10
to Google Visualization API
Here's an exmaple that you can paste in the playground:

function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Percent');

data.addRows(3);
data.setCell(0, 0, 'Tong Ning mu');
data.setCell(1, 0, 'Huang Ang fa');
data.setCell(2, 0, 'Teng nu');
data.setCell(0, 1, 34, '34%');
data.setCell(1, 1, 45, '45%');
data.setCell(2, 1, 86, '86%');


var view = new google.visualization.DataView(data);
view.setColumns([
0,1,
{type: 'number',
label: 'Calculated',
calc: function(dataTable, rowNum){
return dataTable.getValue(rowNum, 1) * 2;
}
}
]);


// Create and draw the visualization.
visualization = new
google.visualization.Table(document.getElementById('table'));
visualization.draw(view);
}


What is the best way to format the calculated column to display the
percentage signs?

Thanks
Laurent

On Jul 9, 3:24 am, ChartMan <chart...@google.com> wrote:
> Can you please give an example of a data input and the required output.
>
> Thanks
> ChartMan
>
>
>
> On Fri, Jul 9, 2010 at 2:26 AM, laurenty <laure...@gmail.com> wrote:
> > Is it possible to specify the pattern of a calculated column in
> > DataView without to use google.visualization.PatternFormat afterwards?
>
> > Thanks
>
> > Laurent
>
> > --
> > 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<google-visualization- api%2Bunsu...@googlegroups.com>
> > .

KeithB

unread,
Jul 10, 2010, 7:30:31 PM7/10/10
to Google Visualization API
Hi Laurent,

It looks like Formatters (a PatternFormat in this case) can only be
applied to DataTables, not DataViews,

http://code.google.com/apis/visualization/documentation/reference.html#formatters

Can you specify the name/type/format of the computed column when
creating the DataTable and leave the values null until you create the
DataView?

Good luck,
K

laurenty

unread,
Jul 11, 2010, 1:43:45 PM7/11/10
to Google Visualization API
Adding extra columns to the DataTable wouldn't work in this case as I
have several views based on the same table and use them with charts.
So you're saying that DataView supports calculated columns but that
there is no way to format the data? That sounds like a design flaw to
me...

I might just need to do all the calculations and formatting on the
server side and use multiple DataTable objects, but this seems
inefficient.

Thanks

Laurent


On Jul 10, 4:30 pm, KeithB <kbornho...@gmail.com> wrote:
> Hi Laurent,
>
> It looks like Formatters (a PatternFormat in this case) can only be
> applied to DataTables, not DataViews,
>
> http://code.google.com/apis/visualization/documentation/reference.htm...

ChartMan

unread,
Jul 12, 2010, 4:19:44 AM7/12/10
to google-visua...@googlegroups.com
Not sure what you are requesting here, if there are any standing issues please describe the bug
or the feature request you are looking for.

Thanks
ChartMan

--
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.

laurenty

unread,
Jul 12, 2010, 12:55:51 PM7/12/10
to Google Visualization API
Hi ChartMan,

Let's say I have a DataTable with 3 columns: name (string), value1
(number) and value2 (number)
and I am formatting columns 1 and 2 with NumberFormat to display as
percentages.
I then create a DataView that will have a 4th column using 'calc' as a
sum of columns 1, 2.
There is no way to format the new calculated column as a percentage
because cannot be used with DataView.

Am I missing something?

Thanks

Laurent

On Jul 12, 1:19 am, ChartMan <chart...@google.com> wrote:
> Not sure what you are requesting here, if there are any standing issues
> please describe the bug
> or the feature request you are looking for.
>
> Thanks
> ChartMan
>
> > google-visualizati...@googlegroups.com<google-visualization-api%2Bunsu...@googlegroups.com>
> > .

Bart van der Wal

unread,
Oct 6, 2015, 6:59:57 AM10/6/15
to Google Visualization API
Hello ChartMan, Laurenty,

I seem to have bumped into this exact issue about 5 years later (october 2015). Sadly it seems it is still impossible in the JavaCharts JS API to apply formatting/a pattern to a DataView.

In my case

var percPattern = view.getColumnPattern(1);
alert(JSON.stringify(percPattern));  // echo's "0.0%"
view.setColumns([0, { sourceColumn: 1, label: 'Coolness factor', type: 'number', ]);
alert(JSON.stringify(view.getColumnPattern(1))); // echo's "0.0%"

I am looking for a way to maintain the formatting, something like:
view.setColumns([0, { sourceColumn: 1, label: mbmChart.vAxisTitle, type: 'number', pattern: '#,#%' } ]); // '#,#%'

Or even a DataView.setColumnPattern() method to match the getter. But sadly there is no such thing.

Am I missing something..?

Regards,
Bart

Bart van der Wal

unread,
Oct 6, 2015, 7:02:41 AM10/6/15
to Google Visualization API
Oops, I forgot to edit, but the second echo in my code example was "null" instead of "0.0%". E.g.:

var percPattern = view.getColumnPattern(1);
alert(JSON.stringify(percPattern));  // echo's "0.0%"
view.setColumns([0, { sourceColumn: 1, label: 'Coolness factor', type: 'number', ]);
alert(JSON.stringify(view.getColumnPattern(1))); // echo's "null"     <--- THE ISSUE
Reply all
Reply to author
Forward
0 new messages