score:0

Accepted answer

when you console log '$("#mychart").get(0)' this will return you undefined, because on rendered your get(0) is not initialized, for prevent this you have to add a callback when you initialized you chart. so your get(0) will be initialized first then you can create your chats.

'$("#mychart").get(0)' is not a reative thing so your view will be not re-initialized.

here is the working code:

function drawchart() {
    var oldcount = 2;
    var newcount = 4;
    var data = [{
        value: newcount,
        color: "#e53935",
        highlight: "#c62828",
        label: "new"
    }, {
        value: oldcount,
        color: "#3949ab",
        highlight: "#1a237e",
        label: "regular"
    }];

    var pieoptions = {
        animation: false,
    }
    // added a callback here.
    settimeout( function(){
        if ($("#mychart").get(0)) {
            var ctx = $("#mychart").get(0).getcontext("2d");
            var mynewchart = new chart(ctx);
            console.log(mynewchart);
            new chart(ctx).pie(data, pieoptions);
        }   
    })
}

Related Query

More Query from same tag