javascript - 如何更改饼图中向下钻取的点格式?

标签 javascript highcharts pie-chart

我正在使用带有向下钻取功能的饼图,有什么方法可以更改工具提示功能中的点格式。我要显示;首先以百分比 (%) 格式绘制饼图,然后以公吨 (MT) 格式向下钻取数据。

我从后端服务获取相应格式的数据。产品以公吨和剩余百分比表示,实际百分比以百分比表示。

我的饼图代码如下。

function visitorData(data){
    var products = data.products;
    var remainingPercentage=data.remainingPercentage;
     var actualPercentage=data.actualPercentage
    Highcharts.chart('current', {
         credits: {
        enabled: false
      },
        chart: {
            type: 'pie'
        },
        title: {
            text: 'Production report of current quarter'
        },
        subtitle: {

        },
        plotOptions: {
            series: {
                dataLabels: {
                    enabled: true,
                }
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
            pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
        },
        series: [{
            name: 'Planned Production',
            colorByPoint: true,
            data: [{
                name: 'Remaining Production Qty. ',
                y: data.remainingPercentage,
            },
             {
                name: 'Actual Production Qty.',
                y: data.actualPercentage,
                drilldown: 'ap'
            }
            ]
        }],
        drilldown: {
            series: [{
                name: 'production report',
                id: 'po',
                data: [

                ]
            }, {
                name: 'Actual Production Qty.',
                id: 'ap',
                data: data.products

            }  ]
        }
    }); 

}

提前致谢。

最佳答案

解决此问题的一种方法是为您的第一个关卡系列指定一个工具提示:{pointFormatter: }。这将覆盖主要的工具提示格式化程序并向您显示您希望其显示的数据。

// Create the chart
 Highcharts.chart('container', {
         credits: {
        enabled: false
      },
        chart: {
            type: 'pie'
        },
        title: {
            text: 'Production report of current quarter'
        },
        subtitle: {

        },
        plotOptions: {
            series: {
                dataLabels: {
                    enabled: true,
                }
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
             //MT format for the lower drilldowns
             pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}MT</b> of total<br/>' 
        },
        series: [{
         tooltip: {
            //Pointformat for the percentage series
            pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>' 
        },
            name: 'Planned Production',
            colorByPoint: true,
            data: [{
                name: 'Remaining Production Qty. ',
                y: 3,
            },
             {
                name: 'Actual Production Qty.',
                y: 5,
                drilldown: 'ap'
            }
            ]
        }],
        drilldown: {
            series: [{
                name: 'production report',
                id: 'po',
                data: [1]
            }, {
                name: 'Actual Production Qty.',
                id: 'ap',
                data: [2]

            },


            ]
        }
    }); 

我选择让第一级覆盖工具提示的原因是因为您的钻取结构,我认为所有这些钻取都将使用相同的工具提示格式。

Here你可以找到一个可用的 JSFiddle。

关于javascript - 如何更改饼图中向下钻取的点格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50524122/

相关文章:

javascript - 来自 Node.js 的 Javascript 中的 getToken 的 invalid_request

javascript - 检测 AJAX 请求调用的 Iframe 滚动事件

javascript - 图表初始化后如何更改 highcharts 事件

Highcharts 自定义渲染器图表和工具提示

javascript - Node.js:从 MongoDB 流式传输到文件

javascript - 在 javaScript 中添加

javascript - 调用函数onclick highchart

pie-chart - 百度隐藏echart饼图中标签

d3.js - 如何在 d3pie 中指定标签字体大小?

iphone - 计算饼图中的旋转角度