Highcharts drilldown未显示饼图的数据

时间:2017-12-14 03:05:03

标签: javascript php laravel charts highcharts

嘿伙计们,所以我试着做一个高清“专栏”并深入到“馅饼”图表。该图表在我调用的数据中工作正常,但是向下钻取饼图并未显示数据值。它看起来像这样: pie chart

正如你可以看到它向我显示“拆分”,实际上我在脚本中硬编码了不同的值。另外,我怎样才能让它仅显示饼图中的百分比?因为我创建了单独的饼图,它显示了使用highcharts的百分比。 我的代码如下:

<div id="container"></div>


<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script>

$(function () {
    var chart;
    $(document).ready(function() {
    
        var colors = Highcharts.getOptions().colors,
            categories = ['Total', 'Match'],
            name = 'chart',
            data = [{
                    y: {!! $countTotalRecord['total'] !!},
                    color: colors[0],
                    drilldown: {
                        name: 'total',
                        categories: ['Low Confidence', 'No Answer', 'Missing Intent', 'Webhook Fail'],
                        data: [{!! $countTotalRecord['low confidence'] !!}, {!! $countTotalRecord['no answer'] !!}, {!! $countTotalRecord['missing intent'] !!}, {!! $countTotalRecord['webhook fail'] !!}],
                        color: colors[0]
                    }
                }, {
                    y: {!! $countTotalRecord['match'] !!},
                    color: colors[1]
                }];
    
        function setChart(options) {
            chart.series[0].remove(false);
            chart.addSeries({
                type: options.type,
                name: options.name,
                data: options.data,
                color: options.color || 'white'
            }, false);
            chart.xAxis[0].setCategories(options.categories, false);
            chart.redraw();
        }
    
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container'
            },
            title: {
                text: 'Chart'
            },
            xAxis: {
                categories: categories
            },
            yAxis: {
                title: {
                    text: ''
                }
            },
            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                var drilldown = this.drilldown;
                                var options;
                                if (drilldown) { // drill down
                                    options = {
                                        'name': drilldown.name,
                                        'categories': drilldown.categories,
                                        'data': drilldown.data,
                                        'color': drilldown.color,
                                        'type': 'pie'
                                    };
                                } else { // restore
                                    options = {
                                        'name': name,
                                        'categories': categories,
                                        'data': data,
                                        'type': 'column'
                                    };
                                }
                                setChart(options);
                            }
                        }
                    },
                    dataLabels: {
                        enabled: true,
                        style: {
                            fontWeight: 'bold'
                        },
                        formatter: function() {
                            return this.y;
                        }
                    }
                },

                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            tooltip: {
                formatter: function() {
                    var point = this.point,
                        s = this.x +':<b>'+ this.y +'</b><br/>';
                    if (point.drilldown) {
                        s += 'Click to view '+ point.category +' data';
                    } else {
                        s += 'Click to return';
                    }
                    return s;
                }
            },
            series: [{
                type: 'column',
                name: name,
                data: data,
                color: 'white'
            }],
            credits:{
              enabled:false
            },
            exporting: {
                enabled: false
            }
        });
    });
    
});


</script>

基本上,我需要知道的两件事是在PIE CHART中显示值和百分比。

0 个答案:

没有答案