Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

highcharts - how to center text inside donut chart embedded in combination chart

I would like to know how to center text and be able to update that text on hover inside of a donut chart that is part of a combination chart.

I have seen solutions using the chart title, verticalAlign and setTitle but that approach doesn't appear to work when the donut chart is part of a combination chart.

I have also tried using a div positioned in the center of the donut chart. That doesn't work well because when the y access labels of the primary series get wider (i.e. more digits) then the donut chart slides to the right and the div is no longer centered on the donut chart.

I have added a jsfiddle that can be used to demonstrate any suggestions you might have on getting rendered text, a title, a div, whatever centered on the donut chart that will also move with that chart.

{type: 'pie',
 name: 'Total consumption',

http://jsfiddle.net/sJfuA/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use renderer to add custom text on your chart. Then you can add events using element.on(). See live example: http://jsfiddle.net/sJfuA/2/

    $('#container').highcharts({
        chart: {
            events: {
                load: function() {
                    var chart = this,
                        rend = chart.renderer,
                        pie = chart.series[4],
                        left = chart.plotLeft + pie.center[0],
                        top = chart.plotTop + pie.center[1],
                        text = rend.text("text", left,  top).attr({ 'text-anchor': 'middle'}).add();

                    text.on("mouseover", function() {
                       alert("hover!"); 
                    });

                }
            }
        }, 
        ...
     });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...