I need to use new chart.js to render the pie charts. However, I don’t know how to use it,
these are the steps I followed:
- Install node.js from installer then restart
- in command prompt: npm install npm -g
- add the canvas id to the place where you want to see the chart
1<span class="hljs-tag"><<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"400"</span>></span><span class="hljs-tag"></<span class="hljs-name">canvas</span>></span> - add the script for the chart
-
123<span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"myChart"</span>);<span class="hljs-keyword">var</span> myChart = <span class="hljs-keyword">new</span> Chart(ctx, {</span>
……………………………..}
-
new Chart is the constructor for the chart.