Okay
  Public Ticket #2849934
Don't show 0 values on graph
Closed

Comments

  • Kim Pham Nguyen started the conversation

    Dear TMS.

    I'm importing data from a MYSQL database to populate a graph. I'm using a line graph, and I do not wish for the graph to draw a line whenever the value is 0. 

    Is this possible?

    Regards, Kim.

  • [deleted] replied

    Hi Kim

    Thank you for reaching out to us.

    You have to make some changes in code in file :

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

    case 'int':    $return_data_row[] = (float)$row[$columnKey];    break;
    case 'float':    $return_data_row[] = (float)$row[$columnKey];    break;

    and replace with this

    case 'int':    if (is_null($row[$columnKey])){        $return_data_row[]=null;    }else{       $return_data_row[] = (float)$row[$columnKey];    }    break;
    case 'float':    if (is_null($row[$columnKey])){         $return_data_row[]=null;    }else{         $return_data_row[] = (float)$row[$columnKey];    }    break;                            

    With this changes you will get charts like on the screenshot (Selection_016.jpg).

    If you want to make charts like on screenshot (Selection_015.jpg) you have to use wpdatachart callbacks and insert that on page where is your chart.

    <script type="text/javascript">
    jQuery(window).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 page.

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

    1539290246.png
    3942732156.png

  • Matt replied

    Hey Blaženka,

    This fix worked for me until current update; now when I change the code at affects no change.  Can you shed any light?

    Many thanks,

    Matt.

  • [deleted] replied

    Hi Matt,

    thank you for contacting backsmile.png

    I will escalate this matter to our senior colleague so that he would give a more experienced advice; he will contact you as soon as possible.

    I wish you a lovely day in the meantime.

  •  2,572
    Aleksandar replied

    Hey Matt

    You'll need to modify some files since we somehow forgot to pass the chart ID in there. Please go to wp-content/plugins/wpdatatables/source/class.wpdatachart.php and on line 1634 you will find this:

     $row[$columnKey] = apply_filters('wpdatatables_filter_int_cell_data_in_charts', $row[$columnKey], $columnKey, $this->_wpdatatable->getWpId());

    Replace it with this:

    $row[$columnKey] = apply_filters('wpdatatables_filter_int_cell_data_in_charts', $row[$columnKey], $columnKey, $this->getId(), $this->_wpdatatable->getWpId());

    In the same file, on line 1642 you will find this:

    $row[$columnKey] = apply_filters('wpdatatables_filter_float_cell_data_in_charts', $row[$columnKey], $columnKey, $this->_wpdatatable->getWpId());

    And you need to replace it with this:

    $row[$columnKey] = apply_filters('wpdatatables_filter_float_cell_data_in_charts', $row[$columnKey], $columnKey, $this->getId(), $this->_wpdatatable->getWpId());

    Again, in the same file, on line 1725 you will find this:

    $cellData = apply_filters('wpdatatables_filter_int_cell_data_in_charts', $this->_wpdatatable->getCell($columnKey, $rowIndex), $columnKey, $this->_wpdatatable->getWpId());

    Replace it with this:

    $cellData = apply_filters('wpdatatables_filter_int_cell_data_in_charts', $this->_wpdatatable->getCell($columnKey, $rowIndex), $columnKey, $this->getId(), $this->_wpdatatable->getWpId());

    Then go to line 1733 of the same file, and find this:

    $floatNumber = apply_filters('wpdatatables_filter_float_cell_data_in_charts', $this->_wpdatatable->getCell($columnKey, $rowIndex),$columnKey , $this->_wpdatatable->getWpId());

    Replace it with this:

    $floatNumber = apply_filters('wpdatatables_filter_float_cell_data_in_charts', $this->_wpdatatable->getCell($columnKey, $rowIndex),$columnKey , $this->getId(), $this->_wpdatatable->getWpId());

    This adds the chart ID in the parameters. You'll only have to do this one time, as it will be included in our next update. 

    Then, go to the functions.php file of your theme or child theme, and add this:

    function filterNullValues ($value, $origHeader ,$chartID, $tableID){
         // You can add conditions for specific org header, chart id or table id
        // Here we only check if value is null and provide same value to the chart object
        if (is_null($value) || $value == 0){
            $value = null;
        }
        return $value;
    }
    add_filter( 'wpdatatables_filter_int_cell_data_in_charts', 'filterNullValues', 10, 4 );
    add_filter( 'wpdatatables_filter_float_cell_data_in_charts', 'filterNullValues', 10, 4 );

    This works for integer and float columns that have NULL values and "0" values.

    We'll include the fix in the next update, so you won't need to change the code after the plugin updates, but you will need to keep this code in functions.php.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Matt replied

    Thanks for your reply Aleksandar,

    Unfortunately this appears to filter every value on all of my charts, not just null/0! :(

  •  2,572
    Aleksandar replied

    Thank you for your feedback, Matt, I forwarded the ticket to our developers for review, and as soon as I hear from them, I will let you know.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  2,572
    Aleksandar replied

    Hey Matt

    I just saw that this was actually resolved in another ticket.

    If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables