Managing 2 different canvas with chart.js



  • Hello,
    I'm trying to draw two different canvas with data that comes through backend API.
    The problem is that sometimes one of the two canvas doesn't have data (and that's correct, it depends on data in backend) but the other does.
    The command window.JSREPORT_READY_TO_START = true; in the <script> tag is working with both of the canvas present, but it doesn't work when one of the two is missing.
    I also used a custom if helper to manage the presence of the canvas, like I'm showing in the playground below.

    Playground Test

    I'm using empty_dataset in each dataset (barChart and pieChart) to control when a canvas is shown or not. If you enable window.JSREPORT_READY_TO_START = true; at the end (line 187) it works but the pieChart is partial (the [1] in the data part should cover the whole pieChart). But if you don't, I would expect this to work with the full pieChart.

    What am I doing wrong?

    Thank you for your time



  • The options shouldn't be nested, so put animation one level up

       options: {
        maintainAspectRatio: false,
        devicePixelRatio: 1.5,
        ...
          options: { // WRONG nesting
              animation: {
                  onComplete: function () {                                     
                         window.JSREPORT_READY_TO_START = true
                   }
            }                 
    

    Btw, this isn't how helpers should be defined

    // WRONG
    Handlebars.registerHelper('custom_if', function (v1, operator, v2, options) {...
    
    // CORRECT
    function custom_if(...)
    


  • @jan_blaha
    What do you mean about the nesting part? I always done like that in other PDFs and it always worked....I thought that was good, how should it be then? Like this?

    options: {
        maintainAspectRatio: false,
        devicePixelRatio: 1.5,
        animation: {
            onComplete: function () {                                     
                window.JSREPORT_READY_TO_START = true
            }
        }  
    

    And about the helper, I put it there because it was a single PDFs, but I have multiple in my project and that helper is defined as a helper tagged to every PDFs,

    Any suggestion about resolving this though?



  • @jan_blaha Sorry i just got back, i was out for a meeting and I answered quickly...too quicky...it seems that was the problem...the nesting animation thing actually...and I double checked, in other PDFs it was correct (no wrong nesting). Thank you, that resolved it!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.