This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Use this hook to add or change the options in your Google chart.
Usage
add_filter('frm_google_chart', 'frm_add_graph_options', 10, 2);
Parameters
- $options - array of graph options
- $args - array of various graph variables
Examples
Move legend
Move the legend above the graph.
add_filter('frm_google_chart', 'frm_move_graph_legend', 10, 2);
function frm_move_graph_legend($options, $args){
$options['legend'] = array('position' => 'top', 'textStyle' => array('fontSize' => 10 ) );
$options['legend']['maxLines'] = 4;
return $options;
}
Add text styling to pie graph
Use the following code to set the text style of the pie graph.
Replace 'red' with the color of your choice. The color can be any HTML color string, for example: 'white' or '#00cc00'. You can read more about the available configuration options here.
add_filter('frm_google_chart', 'frm_pie_chart_styling', 10, 2);
function frm_pie_chart_styling($options, $atts){
if ( $atts['type'] == 'pie' ) {
$options['pieSliceTextStyle'] = array('color' => 'red');
}
return $options;
}
Limit geo graph to specific region
A geo graph will show the entire world, by default. You may only show a specific region with the following code. Replace 'My graph title' with the title set in your graph shortcode. Replace 'IT' with the region of your choice. You may read more about the accepted regions here.
add_filter('frm_google_chart', 'frm_limit_graph_region', 10, 2);
function frm_limit_graph_region( $options, $args ) {
if ( isset( $args['atts']['title'] ) && $args['atts']['title'] == 'My graph title' ) {
$options['region'] = 'IT';
}
return $options;
}
Set title with special characters
Use the following code to set a graph title with special characters.
add_filter('frm_google_chart', 'frm_set_custom_graph_title', 10, 2);
function frm_set_custom_graph_title( $options, $args ) {
if ( isset( $args['atts']['title'] ) && $args['atts']['title'] == 'My graph title' ) {
$options['title'] = 'Test & Testing';
}
return $options;
}
Hide legend in geo chart
A geo chart will show the legend, by default. Use the following code to hide the legend in a geo chart when displayed.
add_filter('frm_google_chart', 'frm_legend_geo_graph', 10, 2);
function frm_legend_geo_graph( $options, $args ) {
$options['legend'] = 'none';
return $options;
}
Disable tooltip in the pie graph
A pie graph will show the tooltip, by default. Use the following code to disable the tooltip in a pie graph when displayed.
add_filter('frm_google_chart', 'frm_pie_chart_tooltip', 10, 2);
function frm_pie_chart_tooltip($options, $atts){
if ( $atts['type'] == 'pie' ) {
$options['tooltip'] = array('trigger' => 'none');
}
return $options;
}
Add an average line or trendlines
This example will allow you to add an average line or trendlines in your google chart.
add_filter( 'frm_google_chart', 'my_custom_function' );
function my_custom_function( $options ) {
$options['trendlines'] = array( 0 => array() );
return $options;
}
if you need to play with color, the array takes some settings: $options['trendlines'] = array( 0 => array( 'color' => 'green' ) );
Set x-axis options
You can use this code to set x-axis options, including those that aren't available as options in the graph shortcode.
add_filter('frm_google_chart', 'frm_add_haxis_options', 10, 2);
function frm_add_haxis_options( $options, $atts ){
$options['hAxis']= array( 'textStyle' => array( 'color' => 'green', 'fontSize' => '18', 'bold'=> true ) );
return $options;
}
Display percentage in pie graph
In the pie graph tooltip, it will show both the total and the percentage by default. Use the following code to display the percentage only.
add_filter('frm_google_chart', 'frm_pie_chart_tooltip_percentage', 10, 2);
function frm_pie_chart_tooltip_percentage($options, $atts){
if ( $atts['type'] == 'pie' ) {
$options['tooltip'] = array('text' => 'percentage');
}
return $options;
}