简体   繁体   English

如何删除无法创建图表:与Ruby on Rails结合使用时,无法从给定项目错误获取上下文?

[英]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.

相关问题 Angular/Chart.js 错误:无法创建图表:无法从给定项目获取上下文 - Angular/Chart.js error: Failed to create chart: can't acquire context from the given item Chart.js 错误:无法创建图表:无法从给定项目获取上下文 - Chart.js Error: Failed to create chart: can't acquire context from the given item 错误:无法创建图表:无法从给定项目获取上下文 - Error: Failed to create chart: can't acquire context from the given item chart.js 无法创建图表:无法从给定项目获取上下文 - chart.js Failed to create chart: can't acquire context from the given item 无法呈现图表 - “无法从给定项目获取上下文” - Failing to render chart – “can't acquire context from the given item” Java 中的实时图表 JS 从传感器获取数据;Chart.js:无法创建图表:无法从给定项目获取上下文 - Realtime chart JS in Java obtaining the data from a sensor ;Chart.js: Failed to create chart: can't acquire context from the given item HighCharts:如何从图表容器中添加或删除“图表上下文菜单”? - HighCharts : How to add or remove "chart context menu" from chart container? 如何在Rails中使用jQuery删除特定项目? - How to remove a particular item using jquery in rails? “失败:尝试创建此媒体项目时出错。” - “Failed: There was an error while trying to create this media item.” 无法从数组Vuex中删除项目 - Can't remove an item from an array Vuex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM