Search code examples
grailsgrails-plugin

Google-Visualization Plugin Grails: How to set hAxis max value and color formatting


I'm using the google-visualization in grails and would like to configure two things:

1) How can I set the maximum value along the horizontal axis?
2) How can I change the bar column if it falls below a certain value?

Here's what I have:

<td>
<div id="${mach.divtag}" style="display:block;">    
<gvisualization:columnCoreChart elementId="${mach.divtag}" width="${150}"
     height="${120}" columns="${mac.columns}" data="${mach.datapoints}"
     title="${mach.name}" />
</div>

Here's a snapshot of what I'm hoping to change in the charts.

enter image description here

Thanks. I really appreciate any help.


Solution

  • From the FAQ:

    Q: How do I set values for a visualization object data type like the column core chart's "hAxis"?

    A: You can easily do this by using an Expando or a custom bean class. "textColor", "title" and "titleColor" are fields of this object.

    From the examples of the plugin

    <gvisualization:columnCoreChart elementId="columnchart" title="Company Performance" width="${400}" height="${240}" hAxis="${new Expando(title: 'Year', titleColor: 'red')}" columns="${companyPerformanceColumns}" data="${companyPerformanceData}" />
    

    Therefore, for a), use an Expando and set the hAxis.maxValue, per the Google API

    hAxis="${new Expando(maxValue:100)}"
    

    for b), you will probably have to do this yourself in Javascript using the Google API to get the bars using a combination of getSelection() for all available bars and setSelection() with some kind of color modifier after you've interrogated its value. Hopefully you can handle it from here, otherwise seek consulting help.