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

Highcharts:是否可能强制datalabel与y轴重叠?

  •  0
  • Codemonkey  · 技术社区  · 8 年前

    是否可以强制“PB”数据标签位于椭圆的中心,以便其与y轴重叠?

    http://jsfiddle.net/w4ez0L4n/

    我准备好了 allowOverlap 到 true 但这似乎只是指其他数据标签,而不是其他图表元素。

    谢谢

    来自JSFIDLE的代码:

    Highcharts.chart('container', {
      chart: {
        type: 'scatter',
        marginRight: 20,
        marginLeft: 20,
        style: {
          fontFamily: 'Helvetica'
        },
        zoomType: 'xy'
      },
      title: {
        text: 'Finish line plot'
      },
      subtitle: {
        text: ''
      },
      xAxis: {
        opposite: true,
        gridLineWidth: 1,
        reversed: true,
        title: {
          text: 'seconds back'
        },
        min: 0
      },
      yAxis: {
        opposite: true,
        gridLineWidth: 0,
        labels: {
          enabled: false
        },
        lineWidth: 2,
        title: {
          text: 'Finish line'
        },
        lineColor: '#000'
      },
      legend: {
        enabled: false
      },
      plotOptions: {
        series: {
          dataLabels: {
            align: 'center',
            allowOverlap: true,
            formatter: function() {
              return this.point.name;
            },
            x: 0,
            y: 10,
            style: {
              textOutline: 'none'
            },
            enabled: true
          }
        },
        scatter: {
          marker: {
            fillColor: '#686',
            symbol: 'url(https://www.iconshock.com/image/Golden/Graphics/ellipse/)',
            width: 40,
            height: 40,
            states: {
              hover: {
                enabled: true,
                lineColor: 'rgb(100,100,100)'
              }
            }
          },
          states: {
            hover: {
              marker: {
                enabled: false
              }
            }
          },
          tooltip: {
            headerFormat: '<b>Competitor info:</b><br>',
            pointFormat: '{point.x} seconds back'
          }
        }
      },
      series: [{
        name: 'Male',
        color: 'rgba(119, 152, 191, .5)',
        data: [{
            x: 0,
            y: 85,
            name: 'PB'
          },
          {
            x: 5.3,
            y: 71.8,
            name: 'VB'
          },
          {
            x: 3.5,
            y: 80.7,
            name: 'SF'
          },
          {
            x: 6.5,
            y: 72.6,
            name: 'RW'
          },
          {
            x: 7.2,
            y: 78.8,
            name: 'LH'
          },
          {
            x: 1.5,
            y: 74.8,
            name: 'CM'
          },
          {
            x: 1.7,
            y: 93.8,
            name: 'SH'
          },
          {
            x: 1.5,
            y: 70.0,
            name: 'TM'
          },
          {
            x: 3.0,
            y: 72.4,
            name: 'WP'
          },
          {
            x: 6.0,
            y: 85.9,
            name: 'DH'
          }
        ]
      }]
    });
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   CannedMoose    8 年前

    请参见 Highcharts documentation

    设置属性 crop 和 overflow 对于 dataLabels 应该做到:

    ...
    series: [{
        dataLabels:{
          crop: false,
          overflow: 'none'
        },
        name: 'Male',
    ...
    

    Fiddle

    推荐文章