Showing percentages in graphs when using separate option values in the form.

By: Karl Equi | Asked: 04/26/2023
ForumsCategory: Code HelpShowing percentages in graphs when using separate option values in the form.
Karl Equi asked 12 months ago

I have to use separate option values in my form in order to be able to filter the graphs the way I need.

So I have an option label like "Satisfied" and a value like "__satisfied__"  

The example below only works for fields where there is no secondary option value - so only "Satisfied"   

In the table produced whenthere ARE secondary option values - the graph data is all set at zero.
If I look at the JS on the page which is generating the graph - the relevant bit looks like ["Satisfied",0],["Unsatisfied",0]] etc etc.

The snippet is targeting the right graph on the page - I can see the tooltip is changing - so it is working - it's just not calculating the percentages correctly.   So I'm guessing there is some mismatch between the php snippet and the label/values when using the secondary option values in the form.  

This is the snippet from the example

add_filter( 'frm_graph_data', 'frm_percentage_graph', 10, 2 ); function frm_percentage_graph( $data, $atts ) { if ( isset( $atts['title'] ) && $atts['title'] == 'Gas by Percentage' ) { $data[0][1] = "Percentage of gas used"; $total = FrmProStatisticsController::stats_shortcode( array( 'id' => 4124, 'type' => 'count' ) ); for ( $i = 1, $l = count( $data ); $l > $i; $i++ ) { $graph_value = 0; if ( $total !== 0 ){ $individual_count = FrmProStatisticsController::stats_shortcode( array( 'id' => 4124, 'type' => 'count', '4124' => $data[$i][0] ) ); $percent = ( $individual_count/ $total ) * 100; $graph_value = round( $percent, 1); } $data[ $i ][1] = $graph_value; } } return $data; }

Does anyone out there with php and Formidable skills know how to make this work - or any pointers I can look into?

Thanks in advance!  

1 Answers
Victor Font answered 12 months ago
Here's a pointer, Formidable's graphing tool is simply an interface to Google's Chart Tools. Anything you can do in Google Graphs you should be able to do in Formidable. Formidable Pro has 11 filters for modifying graphs to your liking. See this:
Victor Font replied 12 months ago

Link to Google Chart Tools:

Victor Font replied 12 months ago

BTW, if Google Charts doesn't provide what you need, try ChartJS.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community