Highcharts.js:scrollable innterText?

时间:2016-12-11 21:26:38

标签: javascript jquery html css highcharts

根据this Highchart示例的代码,我想在点击某个图块时在圆环圆圈的中心显示一些文字。现在是否有可能使显示的文本在不适合圆圈的内部区域时可滚动?

到目前为止我有什么



$(function () {
    var colors = ['#8d62a0', '#ceb3d8', '#d5dddd'];
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'vacation-time-chart',
            type: 'pie',
            height: 300,
            width: 300,
            borderRadius: 0
        },
        credits: {
            enabled: false
        },
        title: false,
        tooltip: {
      formatter: function() {
                     return '<b>'+this.y+'</b>';
                    }
                },
        plotOptions: {
            pie: {
                borderWidth: 6,
                startAngle: 90,
                innerSize: '75%',
                size: '100%',
                shadow: true,
                // {
                //     color: '#000000',
                //     offsetX: 0,
                //     offsetY: 2,
                //     opacity: 0.7,
                //     width: 3
                // },
                dataLabels: false,
                stickyTracking: false,
                states: {
                    hover: {
                        enabled: false
                    }
                },
                point: {
                events: {

                    click: function(){
                        this.series.chart.innerText.attr({text: this.txt});
                    }
                }
                }
            }
        },

        series: [{
            data: [
                {y:40, color: colors[0], txt: 'yoyo'},
                {y:10, color: colors[1],  txt: 'dada'},
                {y:60, color: colors[2],  txt: 'this is a longer text that I would like to be scrollable. this is a longer text that I would like to be scrollable. this is a longer text that I would like to be scrollable. this is a longer text that I would like to be scrollable. this is a longer text that I would like to be scrollable.this is a longer text that I would like to be scrollable. this is a longer text that I would like to be scrollable.'}
            ]
            // data: [
            //     ['Firefox',   44.2],
            //     ['IE7',       26.6],
            //     ['IE6',       20],
            //     ['Chrome',    3.1],
            //     ['Other',    5.4]
            // ]
        }]
    },
     function(chart) { // on complete

        var xpos = '50%';
        var ypos = '53%';
        var circleradius = 102;
        var boundingBox;
        var series = chart.series[0];
        var zones;

    // Render the text
    chart.innerText = chart.renderer.label('Articles mentioning XY', 135, 125).add();
    boundingBox = chart.innerText.getBBox();
    chart.innerText.css({
            display:"inline-block",
            position:"absolute",
            top:"1px",
            width: "150px",
            height:"30px",
            color: '#4572A7',
            fontSize: '12px',
            overflow: 'auto',
            textAlign: 'block'

      }).attr({
            // why doesn't zIndex get the text in front of the chart?
            x: series.center[0] - boundingBox.width / 2 + chart.plotLeft / 2,
            y: series.center[1] + boundingBox.height / 2 + chart.plotTop,
            zIndex: 999
        }).add();
    });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>

<div id="vacation-time-chart" style="min-width: 300px; height: 300px; margin: 0 auto"></div>
<script src="testfile.js"></script>

</body>
</html>
&#13;
&#13;
&#13;

有人可以帮我这个吗?将overflow: auto(或滚动)添加到innterText.css属性似乎不是解决方案。

1 个答案:

答案 0 :(得分:1)

你可以这样做,

function defineInnerData(name, y, obj) { // on complete
        var chart=$("#container").highcharts();       
        $( "#pieChartInfoText" ).remove();       
        var textX = chart.plotLeft + (chart.plotWidth  * 0.5);
        var textY = chart.plotTop  + (chart.plotHeight * 0.5);
        var span = '<span id="pieChartInfoText" style="position:absolute; text-align:center;left: 235px;top:210px;width: 130px;">';
        span += '<span style="font-size: 15px">'+ y +'</span><br>';
        span += '<span style="font-size: 12px">'+ name +'</span>';
        span += '</span>';

        $("#addText").append(span);
        span = $('#pieChartInfoText');
        span.css('left', textX + (span.width() * -0.5));
        span.css('top', textY + (span.height() * -0.5)); 

    }
    defineInnerData("", "Tap the slices of this chart to see more");

并在里面打电话,

series: {
        cursor: 'pointer',
        point: {
          events: {
            mouseOver: function() {
              console.log(this)
              defineInnerData(this.name, this.y, this);
            }
          }
        },

<强> DEMO