Show also data from another column in Barchart?

8 views
Skip to first unread message

Marcelo Soares

unread,
Sep 22, 2011, 6:48:13 PM9/22/11
to google-visua...@googlegroups.com
What if I have a barchart and I want the info card to show more
information than just what it measures?

In the company performance example from the Visualization API, I'd
like to show sales in the bar size but leave the expenses to show only
in the mouseover, in a card like this one:

2004
Sales: 1000
Expenses: 400

Is it possible?

Best,

Marcelo.

asgallant

unread,
Sep 23, 2011, 9:14:45 AM9/23/11
to google-visua...@googlegroups.com
You will have to set the formatted value of the "Sales" column (in this example).  You can set it manually when you build your DataTable:

data.setValue(01{v1000f"1000\nExpenses: 400"});

Or you can use a view to auto-calculate this for you:

/*  creates a view with a calculated column that puts the 
 *  value of column 2 into the tooltip of column 1
 *  assumes:
 *    data is a populated DataTable object
 *    column 1 is labeled 'Sales'
 *    column 2 is labeled 'Expenses'
 *    chart is the Chart Object to draw
 *    options is an object of chart options to draw with
 */
var view new google.visualization.DataView(data);
view.setColumns(0{
    type'number',
    label'Sales',
    calcfunction(dataTablerowNum{
        return {
            vdataTable.getValue(rowNum1),
            fdataTable.getValue(rowNum1'\nExpenses' dataTable.getValue(rowNum2)
        };
    }
});
chart.draw(viewoptions);

Reply all
Reply to author
Forward
0 new messages