Okay
  Public Ticket #2907379
Null values in chart
Closed

Comments

  • IW started the conversation

    Hi, I'm enjoying the use of your wpdatatables a lot, but am facing an issue I can't seem to resolve..

    Basically, I want my wpdatacharts to treat empty cells as that -- null. But currenty they treat the empty cells as 0.

    I have found some previous posts that discuss this, including:

    https://tmsplugins.ticksy.com/ticket/2640252/

    https://tmsplugins.ticksy.com//ticket/2557131/

    https://tmsplugins.ticksy.com/ticket/2758531/

    I used the callback mentioned in these posts to try to resolve the same issue for me (also turned off the "use minified version of Javascript files" option in the settings)

    But I still see the problem persisting. Below is the screenshot of the problematic chart. There are 2 lines here -- the red line sharply drops, but in the original wpdatatable, the last cell is just empty. (the gray line does have a number in the last cell, so it's fine) I don't want the red line to stop just short of the last Y-axis slot)

    4794627191.png

    By the way I used Elementor's text editor to simulate what you did to use the callback (as instructed here) 


    But the callback seems to have no effect on the chart.

    Am I also supposed to modify the /wp-content/plugins/wpdatatables/source/class.wpdatachart.php file? I didn't modify it, thinking only the callback would be needed. Appreciate if you could clarify.

    Another minor question I have is, these callbacks and code changes are erased when the wpdatable plugin is updated, right?

    Also, I understand you should change the id of the chart in the callback, but what if there are multiple charts that needed to be affected?

    Any help would be greatly appreciated. This is quite elemental to my data service. 

    Thank you.

  • [deleted] replied

    Hi IW

    Please download the file attached to my response and replace the file in wp-content/plugins/wpdatatables/source/class.wpdatachart.php with the attached file.

    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.

    If you want to apply it just for NULL values, you can use this code:

    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 = 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 );

    And if you want to apply it just for "0" values, you can use this code:

    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 ($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 );
    

    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.

    If you want to connect data with NULLs skipped, you can use this callback: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-connectnulls-true/

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

    Just make sure to replace [16] with the ID of your chart, ad added for each chart.

  • IW replied

    hi Blaženka, this is quite wonderful. Thank you very much. 

    I know you've gone to great lengths for this, but could you help me with one minor question as I'm not at all familiar with coding.

    In this line below,

    function filterNullValues ($value, $origHeader ,$chartID, $tableID){     

    should I replace $chartID with the actual ID of the chart? If so, in what form, and what if I have multiple charts I want this code to be applied to?

    I tried (assuming the id of the chart I want to effect is 107)

    function filterNullValues ($value, $origHeader ,$107, $tableID){     

    &

    function filterNullValues ($value, $origHeader ,107, $tableID){     

    by the way I got critical errors when I tried the above.

    Would you be able to drop a hint as to how to add chart IDs? and how I can make this apply to all charts I have?

    Thank you again. 





  • IW replied

    No worries, Blaženka, it works!! I didn't have to change anything. Thank you!! Long live WpDataTables!!

  • [deleted] replied

    Hi IW

    Thanks for the update, I'm glad to hear thatsmile.png

    Do let us know if you need any further assistance we are always happy to help.

    Have a wonderful day! 


  • IW replied

    hi Blaženka,

    I've worked on various charts since applying your code today and have noticed one minor thing that might actually be a bug of some sort.

    The first set of code you sent me works brilliantly, the one that works for integer and float columns that have NULL values and "0" values. I have been using this today.

    But I have come to a chart in which some cells are empty and some cells contain zero and I need to show both as they are in the chart. So I used the the second set of code, which is just for NULL values, hoping to show zeros while still keeping nulls as nulls.

    By the way the chart I am trying to create looks like this:

    4271430082.png

    Some of the blue dots are missnig because they are actually zero rather than empty in the original wpdatatable.

    If I apply the second set of code that is just for nulls, this chart will show the missing blue dots that mean zero. But other charts that should treat empty cells as null will display them as zeros. So that's the dilemma.

    Would you be able to check the second code just one more time and see if it checks out. Because the first code works and looks quite similar to the second code, I can't see why the second set wouldn't work properly. But appreciate it if you could check one more time. Thanks very much!




  •  2,498
    Aleksandar replied

    Hey IW

    Sorry for the late response. I just wanna jump in real quick, to ask if you used the Callback for skipping nulls, as Blazenka mentioned in one of her previous responses?

    Unfortunately, if you skip zero values, I don't believe you'll be able to connect the lines - if that's what you want to achieve? 

    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

  • IW replied

    Hi, Aleksandar, sorry for my late response. I've been away for some weeks.


    No, I didn't use a callback. Am I supposed to? There are so many tables and charts that have either empty or "0" cells and I thought it'd be impossible to put a callback in every one of the posts/pages I have such a table or chart. (unless there's a way to do this at once and it applies to all posts/pages)


    I just want WpDataTables to treat empty cells as empty and 0s as 0s. In my tables as well, empty cells in csv files I upload will come out be "0" cells, as in the attached image. I'd like them to be empty. Connecting lines is of secondary importance actually, as long as I can show to customers that empty doesn't mean zero. 


    Thank you!


  •  471
    Isidora replied

    Hey IW,

    Sorry for the late response, we have some agents that have contracted Covid-19, so our team is cut in half.

    Yes if you need to skip nulls in chart you will need to provide callbacks for each chart on every page where you need.

    If you need actual zeros from source then you will remove that condition from hook, so instead of this

    if (is_null($value) || $value == 0){     

     you will use this

    if (is_null($value)){     

    For int and float columns empty string is not proper value, because those types accept numbers and all string will be converted in numbers.

    Best regards.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  • IW replied

    Hi Milan, thanks for your response. I'm circling back to this issue now after dealing with some more critical ones..

    Basically, what I want is to make empty cells show up empty when my CSV files uploaded to wpdatable contain empty cells.

    At the moment, all empty cells are shown as zero. Is there any technical way to display empty cells as empty? 

    Thank you

  •  2,498
    Aleksandar replied

    Hello IW

    Which version of wpDataTables do you have, and how are you creating the table? Are you importing the CSV file, or are you linking the CSV file?

    Rendering NULLs as 0s in numerical columns should've been resolved a few updates ago, so please make sure you're using the latest version of the plugin (3.7.1). If you're still facing this with the new version, please send me the file you're using and tell me how I can replicate the issue locally.

    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

  • IW replied

    Hi Aleksandar,

    I'm currently using Version 3.7.1. I think it's the latest, no..?

    I load my tables from an SQL database. I import CSV files into my database via a third-party SQL manager called Heidisql and then run the SQL command (SELECT * FROM 'database-name`) in wpdatatables.

    I've been quite satisifed with this method because my CSV files (huge with thousands of rows) load quickly. But from a certain point in time, blank cells in these tables would now be rendered as 0. 

    I don't know if it's because there's been a certain change to the plugin, or because tables are now loaded from SQL. It is true I used to load these tables by directly importing CSV files into WPdatatable (which made loading slow so I made myself learn to do it from SQL). I seem to remember blank cells would be left as blank in the old days. 


    By the way, I just run this snippet via Code Snippets which your colleague showed me earlier,

    ____

    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 );

    ____

    in order to ensure WPDataCharts treat nulls as nulls. This works nicely for my charts. But  once again, the problem is blank cells in tables are rendered as 0..


    Thanks so much.

  •  2,498
    Aleksandar replied

    Hello again.

    Our developers believe that, when you're uploading the CSV, the value is an empty string which is neither NULL nor 0.

    You can add a condition for that as well:

    if (is_null($value) || $value == 0 || $value == ''){     

    If that doesn't help, could you provide us with a temporary wp-admin (Administrator) user, FTP, and the database, so we can see everything? Just make sure to send those credentials in a PRIVATE response if the code above doesn't 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