Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Highcharts Rails饼图,如何将标签数据传递到饼图?_Javascript_Ruby On Rails_Charts_Highcharts - Fatal编程技术网

Javascript Highcharts Rails饼图,如何将标签数据传递到饼图?

Javascript Highcharts Rails饼图,如何将标签数据传递到饼图?,javascript,ruby-on-rails,charts,highcharts,Javascript,Ruby On Rails,Charts,Highcharts,我试图让标签显示在ROR中的饼图上。我使用to_json作为参数: <%=raw @students.to_json %> 这在柱状图上的categories:标记下有效,但当我将其应用于饼图时,我会得到一个包含所有标签的字符串,如下所示: 我在这里尝试了一些事情——其中一些显然是错误的。我怎样才能传递我所拥有的数据,但让标签在每个部分上单独显示?如何格式化此文件?谢谢 <script> $(function () { $('#containers7')

我试图让标签显示在ROR中的饼图上。我使用to_json作为参数:

<%=raw @students.to_json %>

这在柱状图上的categories:标记下有效,但当我将其应用于饼图时,我会得到一个包含所有标签的字符串,如下所示:

我在这里尝试了一些事情——其中一些显然是错误的。我怎样才能传递我所拥有的数据,但让标签在每个部分上单独显示?如何格式化此文件?谢谢

<script>
 $(function () {
    $('#containers7').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        title: {
            text: 'Students and Number of Notes in Value and Percentage'
        },
        tooltip: {
            formatter: function() {
                return <%=raw @students.to_json %> + '<b>' + this.point.name +'</b>: '+ this.point.y
            }
        },
        plotOptions: {
            pie: {
                name: <%=raw @students.to_json %>,
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels:{
                    enabled: true,
                    format:  <%=raw @students.to_json %>,
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    },
                    showInLegend: true
                }
            }
        },
        credits: {
                enabled: false
            },
        series: [{
            colorByPoint: true,
            name: <%=raw @students.to_json %>,
            data: <%= @sData %>
        }]
    });
});
</script>

$(函数(){
$(“#集装箱7”).海图({
图表:{
plotBackgroundColor:null,
plotBorderWidth:null,
影子:错,
键入:“馅饼”
},
标题:{
课文:“学生和注释数量的数值和百分比”
},
工具提示:{
格式化程序:函数(){
return+''+this.point.name+':'+this.point.y
}
},
打印选项:{
馅饼:{
姓名:,
allowPointSelect:true,
光标:“指针”,
数据标签:{
启用:对,
格式:,
风格:{
颜色:(Highcharts.theme&&Highcharts.theme.ContractTextColor)| |“黑色”
},
showInLegend:对
}
}
},
学分:{
已启用:false
},
系列:[{
colorByPoint:对,
姓名:,
数据:
}]
});
});

我尝试取出“raw”,但没有任何效果。

这可能是由于将
数据标签的
格式设置为
造成的。
返回什么?嗨,谢谢。我更新了OP。当我取出“原始”时,图表不会显示。但我的问题仍然存在:
返回什么?如果你能用图表使用的示例数据创建一个活生生的例子,比如JSFIDLE,那就容易多了(因此,你可以用可能使用或正在使用的数据代替“原始数据”)。这可能是因为将
数据标签的
格式设置为
返回什么?嗨,谢谢。我更新了OP。当我取出“原始”时,图表不会显示。但我的问题仍然存在:
返回什么?如果您可以创建一个活生生的示例,比如JSFiddle,其中包含图表正在使用的示例性数据(因此,您可以用可能使用或正在使用的数据替换它,而不是去掉“raw”)。