0

I am using Chart.js for Ionic. The charts load fine on the root page but for each page after the root page in the navigation stack the charts show up blank.

Here's the .ts code:

ionViewDidLoad()
{
    this.profile_donutCanvas = <HTMLCanvasElement> document.getElementById("profile_donutChart");
     this.profile_donutCtx = this.profile_donutCanvas.getContext('2d');
     this.profile_donutChart = new Chart(this.profile_donutCtx, {
        type: 'doughnut',
        data: {
            labels: ['', ''],
            datasets: [{
                data: [100, 0],
                backgroundColor: [
                    'rgba(182, 54, 235, 1)',
                    'rgba(255, 255, 255, 1)'
                ],
                borderWidth: 0
            }]
        },
        options: {
            cutoutPercentage: 95,
            legend:{
            display:false
         },
                    tooltips: {
                        enabled:false
                    }
                }
    });
}

and here's the .html code:

<canvas id="profile_donutChart" width="100" height="100" padding></canvas>    

Does anybody know what could possibly cause this?

Thanks, Troy

1
  • Can you please make working copy to stackblitz.com? Commented Jun 27, 2018 at 5:13

1 Answer 1

1

I had similar difficulties using Chart.js in ionic (v3). I solved them using the ng2-charts package, see https://valor-software.com/ng2-charts/ which works fine ony any page of the navigation stack.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.