[英]How to remove Failed to create chart: can't acquire context from the given item error while using it with Ruby on Rails?
I installed frappe charts for ruby on rails through gem. 我通过宝石在轨道上安装了红宝石的冰沙图表。
Then I tried to run one of the frappe-chart code which is given in their website : 然后,我尝试运行他们网站中提供的其中一张frappe-chart代码:
let data = { labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm", "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"], datasets: [ { title: "Some Data", values: [25, 40, 30, 35, 8, 52, 17, -4] }, { title: "Another Set", values: [25, 50, -10, 15, 18, 32, 27, 14] }, { title: "Yet Another", values: [15, 20, -3, -15, 58, 12, -17, 37] } ] }; let chart = new Chart({ parent: "#note-graph", // or a DOM element title: "My Awesome Chart", data: data, type: 'bar', // or 'line', 'scatter', 'pie', 'percentage' height: 250, colors: ['#7cd6fd', 'violet', 'blue'], // hex-codes or these preset colors; // defaults (in order): // ['light-blue', 'blue', 'violet', 'red', // 'orange', 'yellow', 'green', 'light-green', // 'purple', 'magenta', 'grey', 'dark-grey'] format_tooltip_x: d => (d + '').toUpperCase(), format_tooltip_y: d => d + ' pts' });
<canvas id="note-graph"></canvas>
I also tried with div instead of canvas but it's always showing the same error. 我也尝试了div而不是canvas,但是它总是显示相同的错误。
Im using laravel + vuejs. 我正在使用laravel + vuejs。
this solved my problem with "Error: No parent
element to render on was provided." 这解决了我的“错误:未提供要渲染的parent
元素”的问题。 with frapped 陷入困境
with the sample data that the npm provided, 加上npm提供的样本数据,
in de data just declare the data varible like this: 在de data中,只需声明数据变量,如下所示:
<template> <div> <h1>CHARTS</h1> <div id="chart"></div> </div> </template> <script> import { Chart } from 'frappe-charts/dist/frappe-charts.esm.js' // import css import 'frappe-charts/dist/frappe-charts.min.css' export default{ data(){ return{ data : { labels: ["12am-3am", "3am-6pm", "6am-9am", "9am-12am", "12pm-3pm", "3pm-6pm", "6pm-9pm", "9am-12am" ], datasets: [ { name: "Some Data", type: "bar", values: [25, 40, 30, 35, 8, 52, 17, -4] }, { name: "Another Set", type: "line", values: [25, 50, -10, 15, 18, 32, 27, 14] } ] }, chart : null // THIS IS WHAT YOU NEED TO SET NULL } }, methods:{ setChart(){ // IN METHOD YOU SET A NEW CHART this.chart=new Chart("#chart", { title: "My Awesome Chart", data: this.data, type: 'axis-mixed', height: 250, colors: ['#7cd6fd', '#743ee2'] }) } }, mounted(){ this.setChart(); // CALL THE METHOD IN A lifecycle hook } } </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.