setColumnLabel(columnIndex, label) does not work for me

336 views
Skip to first unread message

sebinio

unread,
Aug 25, 2011, 3:09:43 PM8/25/11
to Google Visualization API
Hi all,

I can set the value of the gauge fine but I can not set the column
label from 'today' to 'tomorrow', help! Thanks Sebinio

var gaugeData;
var chart;
var options;

function getMyForm()
{
gaugeData = new google.visualization.DataTable();
gaugeData.addColumn('number', 'today');
gaugeData.addRows(1);
gaugeData.setCell(0, 0, 0);

options = {min:0, max:150, width: 175, height: 175, redFrom: 0,
redTo: 60,
yellowFrom:60, yellowTo: 90, greenFrom:90, greenTo:100,
minorTicks: 5,backgroundColor: '#999999'};

chart = new
google.visualization.Gauge(document.getElementById('menuMyFormChartDiv'));
chart.draw(gaugeData, options);
}

function updateChart()
{
gaugeData.setValue(0, 0, gaugeData.getValue(0, 0) + 25);
alert(gaugeData.getColumnLabel(0)); //returns 1 col
gaugeData.setColumnLabel(0,'tomorrow');
chart.draw(gaugeData, options);
}

asgallant

unread,
Aug 26, 2011, 9:30:35 AM8/26/11
to google-visua...@googlegroups.com
It looks like your code functions just fine.  Normally, the column label does not get displayed as part of the gauge charts.  If you repeat the alert(gaugeData.getColumnLabel(0)); statement, you will see that the column label has changed from 'today' to 'tomorrow'.  What do you expect to happen?

sebinio

unread,
Aug 26, 2011, 11:37:12 AM8/26/11
to Google Visualization API
I was hoping it would change the label on the gauge.

asgallant

unread,
Aug 26, 2011, 12:13:01 PM8/26/11
to google-visua...@googlegroups.com
That's what I suspected >;o)

The DataTable for gauges needs two columns: 1 string and 1 number.  The first column contains the label for the gauge and the second contains the value (see http://code.google.com/apis/ajax/playground/?type=visualization#gauge).  Try this instead:

var gaugeData;
var chart;
var options;

function getMyForm({
    gaugeData new google.visualization.DataTable();
    gaugeData.addColumn('string''day');
    gaugeData.addColumn('number''value');
    gaugeData.addRows(1);
    gaugeData.setCell(00'Today');
    gaugeData.setCell(010);


    options {
        min:0,
        max:150,
        width175,
        height175,
        redFrom0
        redTo60
        yellowFrom:60,
        yellowTo90,
        greenFrom:90,
        greenTo:100,
        minorTicks5,
        backgroundColor'#999999'

    };

    chart new google.visualization.Gauge(document.getElementById('menuMyFormChartDiv'));
    chart.draw(gaugeDataoptions);
}

function updateChart({
    gaugeData.setValue(00'Tomorrow');
    gaugeData.setValue(01gaugeData.getValue(0125);
    chart.draw(gaugeDataoptions);
}



There seems to be a bug (or undocumented feature?) where the label isn't updated when the gauge is redrawn.  I suspect this is because calling draw() on a gauge after it has been drawn once invokes an animation rather than a straight up redraw.  Maybe this would work better:

var gaugeData new google.visualization.DataTable();    
gaugeData.addColumn('string''day');
gaugeData.addColumn('number''value');
gaugeData.addRows(1);

function getMyForm(labelvalue{
    gaugeData.setCell(00label);
    gaugeData.setCell(01value);

    var options {

        min:0,
        max:150,
        width175,
        height175,
        redFrom0
        redTo60
        yellowFrom:60,
        yellowTo90,
        greenFrom:90,
        greenTo:100,
        minorTicks5,
        backgroundColor'#999999'
    };

    var chart new google.visualization.Gauge(document.getElementById('menuMyFormChartDiv'));
    chart.draw(gaugeDataoptions);
}

function updateChart({
    getMyForm('Tomorrow'gaugeData.getValue(0,125);
}



You'll need to pass the 'label' and 'value' parameters to it the first time you call the function. The downside is that you lose the animation with this method.

sebinio

unread,
Aug 26, 2011, 12:55:17 PM8/26/11
to Google Visualization API
Thanks for your help mate. The later is what I'm doing to get around
it, I was just hoping for more eloquent solution but I kind of
understand why it doesn't but it would be nice if it could, like you
can with value.

Jinji

unread,
Aug 29, 2011, 2:22:45 PM8/29/11
to google-visua...@googlegroups.com
Thanks for reporting this issue.


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


Reply all
Reply to author
Forward
0 new messages