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

时间:2018-02-16 21:00:06

标签: javascript html ruby ruby-on-rails-3 frappe

我通过宝石在铁轨上安装了红宝石的冰沙图。

然后我尝试运行其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>

我也尝试使用div而不是画布,但它总是显示相同的错误。

1 个答案:

答案 0 :(得分:0)

我正在使用laravel + vuejs。

这解决了我的问题,出现了“错误:未提供要渲染的parent元素。”茫然

包含npm提供的示例数据,

在数据中只是这样声明数据变量:

<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>