frm_graph_data

Back to Top
Knowledge BaseDisplay Data → frm_graph_data

This hook will allow you to manipulate all the data in a graph, including the labels, rows, and columns.

Usage

add_filter('frm_graph_data', 'change_my_graph', 10, 2);

Parameters

  • $data (array)
  • $atts (array)

Examples

Formidable Hook - Helpful

Basic Example

Submitted by  — 7 years ago

This example will add a row of data to a graph.

add_filter('frm_graph_data', 'my_custom_graph_data', 10, 2);
function my_custom_graph_data( $data, $atts ) {
    if ( $atts['fields'] == array( 100, 101, 102 ) ) ) {
        $data[] = array( 'X-axis label', 10, 20, 30 );
    }
    return $data;
}
Formidable Hook - Helpful

Change x-axis labels

Submitted by  — 7 years ago

Change the x-axis labels in your graph. Change First Label, Second Label, and Third Label to your new x-axis graph labels. Replace 100, 101, and 102 with the IDs of the fields that you're graphing.

add_filter('frm_graph_data', 'change_my_graph_labels', 10, 2);
function change_my_graph_labels( $data, $atts ) {
if ( $atts['fields'] == array( 100, 101, 102 ) ) ) {
    $new_labels = array( 'First label, 'Second label', 'Third label' );

    foreach ( $new_labels as $key => $label ) {
        $row_key = $key + 1;
        if ( isset( $data[ $row_key ] ) ) {
            $data[ $row_key ][0] = $label;
        }
    }
}
return $data;
}
If you would like to add your own example, click here.

Change Log

Last changed in version 2.02.05

Have something to add?

Click here to provide feedback on this page.