【问题标题】:highcharts donut chart center text overlaps with tooltiphighcharts 圆环图中心文本与工具提示重叠
【发布时间】:2015-04-28 11:33:58
【问题描述】:

我在 Highcharts 圆环图/饼图的中心显示文本。 但我的问题是中心文本与工具提示文本重叠,工具提示变得不可读。

我已尝试更改工具提示的 zIndex 以将其置于最前面,但它不起作用。我希望工具提示位于甜甜圈中心文本之上。

在此处查看完整图表:http://jsfiddle.net/SufianRashid/88q5uke1



//==================== HIGH CHARTS =========================//
function RenderPieChart(chartId, chartData, donutCenterText) {
    $('#' + chartId).highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 0,
            plotShadow: false,
            height: 270
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        title: {
            text: '',
            align: 'center',
            verticalAlign: 'middle',
            y: 0,
            useHTML: true
        },
        tooltip: {
            backgroundColor: 'white',
            useHtml: true,
            //zIndex: 99, //on top of everything
            headerFormat: '',
            pointFormat: '{point.actualCounts} {point.name}'
        },
        plotOptions: {
            pie: {
                dataLabels: {
                    formatter: function () { if (this.y != 0) return this.y + '%'; },    //don't show 0% values
                    enabled: true,
                    distance: -25,  //change this value to show label inside/outside the pie chart (negative means towards inside)
                    style: {
                        fontWeight: 'bold',
                        color: 'white',
                        textShadow: '0px 1px 2px black'
                    }
                },
                //showInLegend: true,
                startAngle: 0,
                endAngle: 360,
                center: ['50%', '50%']
            },
            //-------- On click open drill down url --------//
            series: {
                cursor: 'pointer',
                point: {
                    events: {
                        click: function () {
                            location.href = this.options.url;   //same window
                        }
                    }
                }
            }//End adding link
            //--------------------------------//
        },
        series: [{
            type: 'pie',
            innerSize: '140px',
            //--------------------//
            data: chartData
            //--------------------//
        }]
    },
        //-------- Show Center Text ------//
        function (chart) {

            var xpos = chart.plotLeft + (chart.plotWidth * 0.43);
            var ypos = chart.plotTop + (chart.plotHeight * 0.4);


            // Render the text 
            chart.innerText = chart.renderer.html(donutCenterText, xpos, ypos).add();

        }
    );  //EOF: HighChart
}

【问题讨论】:

    标签: javascript html highcharts donut-chart


    【解决方案1】:

    尝试以下将解决您的问题:

    CSS:

    .highcharts-tooltip span {
        background-color:white;
        border:1px solid;
        opacity:1;
        z-index:9999 !important;
    }
    

    jQuery:

    tooltip: {
               borderWidth: 0,
               backgroundColor: "rgba(255,255,255,0)",
               shadow: false,
               useHTML: true,
               //zIndex: 99, //on top of everything
               headerFormat: '',
               pointFormat: '{point.actualCounts} {point.name}'
             },
    

    检查:

    RenderPieChart(
    'PieChartContainer', 
    [
    { name: 'tickets opened within 24 hrs', y: 76.5, actualCounts: 54, url:'../dummyUrl.html' },
    { name: 'tickets opened within 25 to 48 hrs', y: 6.9, actualCounts: 77, url:'../dummyUrl.html' },
    { name: 'tickets opened in 49 to 72+ hrs', y: 93.1, actualCounts: 1032, url:'../dummyUrl.html' }
    ],
    "<span id='DonutCenterText' style='text-align:center;' class='donutValuesOpen'><span>Total Open <br/>Tickets: <a href='../dummyUrl.html'> 1109 </a> <br/> </span><span class='Avg'>Average Days <br/>Open: 8 </span> </span>"
    );
    
    //==================== HIGH CHARTS =========================//
            function RenderPieChart(chartId, chartData, donutCenterText) {
                $('#' + chartId).highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: 0,
                        plotShadow: false,
                        height: 270
                    },
                    credits: {
                        enabled: false
                    },
                    exporting: {
                        enabled: false
                    },
                    title: {
                        text: '',
                        align: 'center',
                        verticalAlign: 'middle',
                        y: 0,
                        useHTML: true
                    },
                    tooltip: {
                        borderWidth: 0,
                        backgroundColor: "rgba(255,255,255,0)",
                        shadow: false,
                        useHTML: true,
                        //zIndex: 99, //on top of everything
                        headerFormat: '',
                        pointFormat: '{point.actualCounts} {point.name}'
                    },
    
                    plotOptions: {
                        pie: {
                            dataLabels: {
                                formatter: function () { if (this.y != 0) return this.y + '%'; },    //don't show 0% values
                                enabled: true,
                                distance: -25,  //change this value to show label inside/outside the pie chart (negative means towards inside)
                                style: {
                                    fontWeight: 'bold',
                                    color: 'white',
                                    textShadow: '0px 1px 2px black'
                                }
                            },
                            //showInLegend: true,
                            startAngle: 0,
                            endAngle: 360,
                            center: ['50%', '50%']
                        },
                        //-------- On click open drill down url --------//
                        series: {
                            cursor: 'pointer',
                            point: {
                                events: {
                                    click: function () {
                                        location.href = this.options.url;   //same window
                                    }
                                }
                            }
                        }//End adding link
                        //--------------------------------//
                    },
                    series: [{
                        type: 'pie',
                        innerSize: '140px',
                        //--------------------//
                        data: chartData
                        //--------------------//
                    }]
                },
    
    
    //------- Show Donut center text ------------------//
                function (chart) {
    
                    var xpos = chart.plotLeft + (chart.plotWidth * 0.43);
                    var ypos = chart.plotTop + (chart.plotHeight * 0.4);
    
                
                    // Render the text 
                    chart.innerText = chart.renderer.html(donutCenterText, xpos, ypos).add();
    
                }
                );  //EOF: HighChart
            }
        .highcharts-tooltip span {
            background-color:white;
            border:1px solid;
            opacity:1;
            z-index:9999 !important;
        }
    
       
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    
    <div id="PieChartContainer" style="height: 400px"></div>

    【讨论】:

    • 这行得通。谢谢。因此,您在创建 highchart 时删除了工具提示的样式,然后从 CSS 中应用它们。我不能在工具提示中使用 'style:' 属性吗?
    • @SufianRashid 是的。我不会在 highchart 中工作更多,但据我所知没有。不过,你可以试试。但是你可以给出 gievn 风格。检查api.highcharts.com/highcharts#tooltip
    • 希望上面的链接有帮助。如果它解决了您的问题,您将其标记为答案。
    猜你喜欢
    • 2020-06-26
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多