Okay
  Public Ticket #2714114
ignoring empty values
Closed

Comments

  • Matt Ling started the conversation

    Is there a way to have Charts ignore empty values? For instance I have a column that may have some blank rows depending on the values of other fields.

    I need to ignore those empty fields so that they are not used when creating a chart. (a column with 10 rows, 8 are empty, 2 are populated should only include 2 results in the chart)


    Is this possible?  

  • [deleted] replied

    Hi Matt

    Thank you for reaching out to us.

    By default, integer and float columns need to have numerical data in them, meaning NULL is not a valid cell value, so it will be replaced by a 0.

    I can try and help you out, but you have to make some changes in code in file :

    /wp-content/plugins/wpdatatables/source/class.wpdatachart.php around line 1631:

    case 'int':   $return_data_row[] = (float)$row[$columnKey]; break;   case 'float':     if ($decimalPlaces != -1){       $return_data_row[] = (float)number_format(         (float)($row[$columnKey]),         $decimalPlaces,         '.',         $thousandsSeparator ? '' : '.');       }else {           $return_data_row[] = (float)$row[$columnKey];       }
    break;

    and replace it with this

    case 'int':                                if (is_null($row[$columnKey])){                                    $return_data_row[]= null;                                }else{                                    $return_data_row[] = (float)$row[$columnKey];                                }                                break;                            case 'float':                               if ($decimalPlaces != -1) {                                   if (is_null($row[$columnKey])) {                                       $return_data_row[] = null;                                   }else {                                       $return_data_row[] = (float)number_format(                                           (float)($row[$columnKey]),                                           $decimalPlaces,                                           '.',                                           $thousandsSeparator ? '' : '.');                                   }                               } else {                                   if (is_null($row[$columnKey])) {                                       $return_data_row[] = null;                                   }else {                                       $return_data_row[] = (float)$row[$columnKey];                                   }                               }                                break;                        

    With these changes you will get charts like on the first screenshot below.

    If you want to make charts like on screenshot #2 you have to use wpdatachart callbacks and insert that on page where your chart is.

    <script type="text/javascript">
    jQuery(window).on('load',function(){    if( typeof wpDataChartsCallbacks == 'undefined' ){ wpDataChartsCallbacks = {}; }        wpDataChartsCallbacks[39] = function(obj){                obj.options.plotOptions.series= {connectNulls: true};            }
    });
    </script>

    One more thing you have to change in this callback number 39 in (wpDataChartsCallbacks[39]) to id of the chart that you use on the page.

    This will be overwritten on next update so you have to come back here and do it again.

    1539290246.png
    3942732156.png

    I hope this helps.