Hey there, Awesome Customers!

Just a heads up: We'll be taking a breather to celebrate International Workers' Day (May 1st and 2nd - Wednesday and Thursday) and Orthodox Easter from Good Friday (May 3rd) through Easter Monday (May 6th). So, from May 1st to May 6th, our team will be off enjoying some well-deserved downtime.

During this time, our customer support will be running on a smaller crew, but don't worry! We'll still be around to help with any urgent matters, though it might take us a bit longer than usual to get back to you.

We'll be back in action at full throttle on May 7th (Tuesday), ready to tackle your questions and requests with gusto!

In the meantime, you can explore our documentation for Amelia and wpDataTables. You'll find loads of helpful resources, including articles and handy video tutorials on YouTube (Amelia's YouTube Channel and wpDataTables' YouTube Channel). These gems might just have the answers you're looking for while we're kicking back.

Thanks a bunch for your understanding and support!

Catch you on the flip side!

Warm regards,

TMS

Okay
  Public Ticket #2640252
Smoother lines and plotting empty values
Closed

Comments

  • Dave started the conversation

    Hello,

    Can you advise on how to plot empty values so that they are not rendered in the chart? right now we have zeros for empty values and they show up as horizontal line - which should NOT  be rendered let me show the chart

    Pasteboard - Uploaded Image


    also these are called spline charts - but they do not smooth the data - is there a way to make them more curvy?


  •  2,499
    Aleksandar replied

    Hello Dave

    If you have zeros in your table, that is an issue we've been dealing with, because integer and float columns cannot have anything other than numbers in them, the plugin is treating an empty cell as "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.


    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

  • Dave replied

    thank you Aleksandar - is there a way to make spline charts more smooth? currently they are not different from simple line charts  as you cane see in the attached image below the lines are not very smooth - is there a special parameter in hicharts that I can change to make spline charts more smooth?

  •  2,499
    Aleksandar replied

    Hello again Dave

    Spline charts have smooth lines by default.

    3822929493.png

    In this example, the green is a spline line, and the blue one behind it is a line, so you can see that spline is rather smooth, and line is sharp.

    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

  • Dave replied

    I am suing the code below and the spline chart still connects to the zeros from the last points on the charts...

    here is how this looks:


    zeroes.png

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

    I changed 39 to 16 as the callback id to chart id



  •  2,499
    Aleksandar replied

    Hello Dave.

    Did this callback work for you before? I know I've tested it in the past, and it used to work, but I can't get it to work on my local environment either.

    I forwarded the callback to one of our developers, so he can take a look at it, and as soon as I hear from him I will let you know. Please note, though, that using callbacks requires some coding knowledge, and included support refers only to advice, so I can't guarantee anything.

    I'm pretty confident that we'll be able to get to the bottom of this, as this is a simple placeholder, and it used to work. As soon as I hear from our developer, 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

  • Dave replied

    Fantastic - I will wait to hear from you! I will note that it did not work before

  •  2,499
    Aleksandar replied

    Hi again Dave

    I need to watch out for terminology in the futuresmile.png

    Your initial comment on this ticket was this:

    Can you advise on how to plot empty values so that they are not rendered in the chart?

    So, I assumed you were referring to NULL values, not zeros, even though you commented that they are saved as zeros right below that. Sorry about the misunderstanding. Empty (NULL) values, are different from zeros ( 0 ), and the code that I sent you works when the data in the columns is saved as NULL in the database. Since you have them saved as zeros, this code won't work.

    To use this callback for tables with zeros, you need to change the code in file /wp-content/plugins/wpdatatables/source/class.wpdatachart.php around line 1631 from:

    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;

    To this:

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

    The difference between this, and what I previously sent is this:

    This is used when data in the database (in your table) is saved with empty values (NULL):

    if (is_null($row[$columnKey])){

    And the code that I just posted above is used when the data is saved with zeros:

    if ($row[$columnKey] == 0) {

    When you apply the code above, and use the same callback I provided in my initial response, it will work. I just tested it locally, and it works fine.

    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

  • Dave replied

    Superb! it works - thanks a lot! LET ME SHOW YOU


    waves2.png


    MUCH BETTER - LAST POINTS DO NOT SHOW ANY ABRUPT DECLINE TO ZERO....now I need to remove those markers - can your callback be easily modified to remove them?

  • Dave replied

    I added this line and it worked! no markers found!!!! 


    obj.options.plotOptions.series.marker = { enabled: false };

  •  2,499
    Aleksandar replied

    Great news, Dave

    Thank you for letting me know.

    Can you please show me how the table looks like, what chart you used, and which callback exactly, and I'll add it to our FAQ section (when I have time).

    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

  • Dave replied

    Sure - here is the callback that I use:

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

    image used is Spline Chart. Zeroes used to show future chart values. The charts will be used to show intraday waves - will be constantly updated through the day - therefore needed the last values to NOT connect to zero.

    here is the snapshot:

    waves3.png

  •  2,499
    Aleksandar replied

    Awesome, Dave, thanks!

    Just a screenshot of the table, please, and I'll leave you to your worksmile.png

    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

  •  1
    Petr replied

    Hi,

    I am trying to set the same behavior for my charts, but the plugin code changed, and I don't know which of its part to replace to stop plotting the empty values (line chart - chart.js).

    Aleks, could you help me out, please? 

  •  1,693
    Miloš replied

    Hi, Petr 

    If you need a workaround for charts to "skill NULL and 0 values",

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


    You don'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.

    Let us know if that works for your use-case. Thanks

    Kind Regards, 

    Miloš Jovanović
    [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

  •  1
    Petr replied

    Hi Miloš,

    I've just tested it, and it doesn't work.

    I also tried the callback, which also didn't affect the chart. 

    By the way, I've added the functions to my theme using the Shortcoder plugin. 

  •  1,693
    Miloš replied

    Hi, Petr.

    Could you please open a new ticket from your account,

    then we can ask you for WP-Admin remote access, if thats'OK,  so we can inspect how you added this on your site and why it is not working.

    When we try the same method, it is working to "skip NULL /blank" values on our charts on all our testing sites,

    and so far for all other users that requested it,  it also works for them.

    So, it might be due to something with the Shortcoder plugin, but not sure.

    Did you try to add the said function directly in your functions.php file of the Theme?

    In either case, we can certainly check this out remotely and try to debut the issue on your site - but if you can make a new ticket, so that we can privately exchange the access URL + Admin credentials in Private messages, for safety reasons.

    Thank you.

    Kind Regards, 

    Miloš Jovanović
    [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