代码之家  ›  专栏  ›  技术社区  ›  TheRealPapa

高图表仪表使工具提示保持可见和居中

  •  1
  • TheRealPapa  · 技术社区  · 10 年前

    当调整屏幕大小时,我无法使我的高图表仪表的指针出现并保持在仪表内可见和居中。

    在我的提琴中,你可以看到工具提示在一小段时间后出现。此外,调整窗口大小时,它不会保持在仪表的中心。

    感谢任何帮助。我的 JSFIDDLE 在这里。

        gaugeChartObj = new Highcharts.Chart({
            credits: false,
            chart: {
                renderTo: divID,
                type: 'solidgauge',
                marginTop: 30,
                events: {
                    load: function(){
                        var p = this.series[0].points[0];
                        this.tooltip.refresh(p);
                    }
                }
            },
            title: {
                text: dataC.title,
                style: {
                    fontSize: '16px'
                }
            },
            exporting: {
                enabled: false
            },
            tooltip: {
                borderWidth: 0,
                backgroundColor: 'none',
                useHTML: true,
                shadow: false,
                style: {
                    fontSize: '16px'
                },
                formatter: function() {
                    return '<div style="width:100%;text-align:center;"><span style="font-size:1.2em;font-weight:bold;">' + this.point.series.name + '</span><br/><span style="font-size:3em;color:' + Highcharts.getOptions().colors[0] + ';font-weight:bold;">' + Highcharts.numberFormat(this.y / 10, 0) + '</span>';
                },
                positioner: function (labelWidth) {
                    return {
                        x: 170 - labelWidth / 2,
                        y: 125
                    };
                }
            },
            pane: {
                startAngle: 0,
                endAngle: 360,
                background: [{
                    outerRadius: '106%',
                    innerRadius: '94%',
                    backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
                    borderWidth: 0
                }]
            },
            yAxis: {
                min: 0,
                max: 100,
                lineWidth: 0,
                tickPositions: []
            },
            plotOptions: {
                solidgauge: {
                    borderWidth: '12px',
                    dataLabels: {
                        enabled: false
                    },
                    linecap: 'round',
                    stickyTracking: true
                }
            },
            series: [{
                name: 'Subscriptions',
                borderColor: Highcharts.getOptions().colors[0],
                data: [{
                    color: Highcharts.getOptions().colors[0],
                    radius: '100%',
                    innerRadius: '100%',
                    y: dataC.seriesData
                }]
            }],
            lang: {
                noData: "No data to display"
            },
            noData: {
                style: {
                    fontWeight: 'bold',
                    fontSize: '15px',
                    color: '#333333'
                }
            }
        });
    
    1 回复  |  直到 10 年前
        1
  •  5
  •   Grzegorz Blachliński    10 年前

    您可以使用dataLabels而不是工具提示在solidgauge图表中显示居中信息: http://api.highcharts.com/highcharts/plotOptions.solidgauge.dataLabels

    dataLabels: {
          enabled: true,
          y: -40,
          borderWidth: 0,
          backgroundColor: 'none',
          useHTML: true,
          shadow: false,
          style: {
            fontSize: '16px'
          },
          formatter: function() {
            return '<div style="width:100%;text-align:center;"><span style="font-size:1.2em;font-weight:bold;">' + this.point.series.name + '</span><br/><span style="font-size:3em;color:' + Highcharts.getOptions().colors[0] + ';font-weight:bold;">' + Highcharts.numberFormat(this.y / 10, 0) + '</span>';
          }
    },
    

    在这里,您可以看到它是如何工作的: http://jsfiddle.net/ujmxxf03/10/