SirBT
SirBT

Reputation: 1698

How do I resolve the "ctx is not defined" issue?

I am having issues using the em0ney:chartjs package, which is a meteor package to display graphic charts. I cant seem to be able to get any graphs to display inside the cavnvas/template. Can someone kindly help me.

Following is the code in my template:

<template name="detail">
    {{>chartCanvas2 id='chartCanvasId' width="300" height="400" }}
</template>

...and below my chartCanvas2 template:

<template name="chartCanvas2">
   <div id="graphs">
      Displaying from "chartCanvas2" template!
      {{myGraphix}}
   </div>   
</template>

and below my helper file:

Template.chartCanvas2.helpers({

'myGraphix' : function () {     
var chartCanvasId = new Chart(ctx, {
        type: 'bar',
        data:{
            labels: ["One", "Two", "Three" ],
         datasets: [{ 
                        label:"# of Votes",
                         data: [12, 34, 50],
          backgroundColor: [
            'rgba(255, 99, 132, 0.1)',
            'rgba(75, 299, 12, 0.1)',
            'rgba(25, 199, 32, 0.1)'
            ],           

         borderColor:[
            'rgba(52, 209, 12, 1)',
            'rgba(52, 209, 12, 1)',
            'rgba(52, 209, 12, 1)'
             ],

         borderWidth: 1
             }],

    },

    options: {
        scales: {
            yAxes:[{
                ticks: {
                    beginAtZero:true                    
                }   

                }]          
        }       
    }
});     
 return chartCanvasId;

},

}); 

Displaying from "chartCanvas2" template! Only displays in the canvas where the graph is suposted to display.

The error message in the console: Exception in template helper: ReferenceError: ctx is not defined

How do I fix this?

Upvotes: 3

Views: 4527

Answers (0)

Related Questions