Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

frm_google_chart

Last Updated: May 31, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Display Data → frm_google_chart
Heads up!
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.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

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;
}
  • Usage
  • Parameters
  • Examples
    • Move legend
    • Add text styling to pie graph
    • Limit geo graph to specific region
    • Set title with special characters
    • Hide legend in geo chart
    • Disable tooltip in the pie graph
    • Add an average line or trendlines
    • Set x-axis options
    • Display percentage in pie graph
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable FormsĀ® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews