2013-05-06 112 views
3

我使用高图创建了蜘蛛网图,但是我在顶部和底部标签中获得重叠标签。我尝试包装它们,并试图错开标签,但我无法阻止它们重叠。Highcharts蜘蛛网标签重叠(顶部和底部)

$(function() { 
$('#spiderchartFull').highcharts({ 
    chart: { 
     polar: true, 
     type: 'line', 
     marginLeft: 120, 
     marginRight: 120 
    }, 
    title: { 
     text: 'Liste des interdépendances a la biodiversité et aux services écologiques' 
    }, 
    subtitle: { 
     text: 'Détaillé' 
    }, 
    xAxis: { 
     categories: [ 
      'Production végétale', 
      'Production animale', 
      'Produits biotiques marins', 
      'Produits biotiques d\'eau douce', 
      'Aquaculture', 
      'Eau potable', 
      'Matières minérales', 
      'Energie renouvelable issue du vivant', 
      'Energie non renouvelable issue du vivant', 
      'Energie renouvelable abiotique', 
      'Dépollution', 
      'Assimilation des déchets', 
      'Régulation des flux gazeux', 
      'Régulation des flux hydriques', 
      'Régulation des phénomènes érosifs', 
      'Régulation de la qualité de l\'air', 
      'Régulation de la qualité de l\'eau', 
      'Régulation de la qualité des sols', 
      'Régulation du climat global', 
      'Régulation du climat local', 
      'Maintenance du cycle de vie et protection des habitats', 
      'Régulation des pathogènes et parasites', 
      'Conservation des stocks génétiques', 
      'Recherche scientifique', 
      'Education', 
      'Esthétiques et culturels', 
      'Religieux', 
      'Récréation', 
      'Volontariat'], 
     labels: { 
      style: { 
       fontSize: '13px', 
       fontFamily: 'Verdana, sans-serif', 
       width: 150, 

      } 
     }, 
     tickmarkPlacement: 'on', 
     lineWidth: 0, 
    }, 
    yAxis: { 
     gridLineInterpolation: 'polygon', 
     lineWidth: 0, 
     min: 0, 
     max: 5, 
     title: { 
      text: 'Rainfall (mm)' 
     } 
    }, 
    tooltip: { 
     headerFormat: '<span style="font-size:10px">{point.key}</span><table>', 
     pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + 
      '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', 
     footerFormat: '</table>', 
     shared: true, 
     useHTML: true 
    }, 
    plotOptions: { 
     column: { 
      pointPadding: 0.2, 
      borderWidth: 0 
     } 
    }, 
    series: [{ 
     name: 'Dépendances aux SE', 
     data: [1.0, 2.0, 3.6, 4.7, 5.0, 1.1, 2.75, 4.33, 4.43, 3.52, 1.0, 2.0, 3.6, 4.7, 5.0, 1.1, 2.75, 4.33, 4.43, 3.52, 1.0, 2.0, 3.6, 4.7, 5.0, 1.1, 2.75, 4.33, 4.43], 
     pointPlacement: 'on' 
    }, { 
     name: 'Transactions monétaires associées', 
     data: [2.0, 3.0, 2.6, 1.7, 1.0, 1.3, 2.235, 4.323, 4.43, 4.52, 2.0, 1.0, 3.6, 3.7, 5.0, 1.1, 2.75, 4.33, 4.43, 3.52, 1.0, 2.0, 3.6, 4.7, 5.0, 1.1, 2.75, 4.33, 4.43], 
     pointPlacement: 'on' 
    }], 

    legend: { 
     itemStyle: { 
      width: 100 
     }, 
    } 
}); 

});

在这里你可以看到我创建的highchart:http://jsfiddle.net/Rfaav/4/

+0

我建议更改图表的大小,因为你有太多的datalabels和身体是不可能将其定位为小格。 – 2013-05-07 12:27:20

+0

DIV的大小不是问题(改变它会导致同样的问题)。问题是标签和图形之间的间距。如果有一种方法可以添加边距或填充以使标签距离比标签更远以解决重叠问题。 – Androidus 2013-05-07 20:06:18

+0

嘿,我面临同样的问题。 – Neelam 2013-05-26 15:16:17

回答

0

我也正面临着同样的疑难问题解决了它使用“useHTML”和我自己的一些JavaScript。 以下是代码。

xAxis: { 
    categories: [], 
    tickmarkPlacement: 'on', 
    lineWidth: 0, 

    labels: { 
     useHTML: false, 
     style: { 
      width: '240px' 
     } 
       , 
     formatter: function() { 
      if ('Is an ideal holiday destination' === this.value) { 
       return '<span id="spn_itisideal"><span style="">' + this.value + '</span>'; 

      } 
      else if ('Is a modern and trendy place' === this.value) { 
       return '<span id="spn_isamodern"><span style="">' + this.value + '</tspan>'; 
      } 
      else if ('Is a popular destination' === this.value) 
      { return '<span id="spn_isapopular"><span style="">' + this.value + '</span>'; } 
      else if ('Has great infrastructure' === this.value) 
      { return '<span id="spn_hasgreatinfrastructure"><span style="">' + this.value + '</span>'; } 
      else { 
       return this.value; 
      } 
     } 
    } 
}, 

当设置useHTML为true,则x轴标签都呈现为html.I挑选那些在格式化功能重叠的标签和将它们包装起来以与相应的ID的跨度。 我的图表加载后,我使用JavaScript函数来调用这些跨度,并根据我的意愿调整它们。

function alterWebChart() {//Adjust x-axis label span. 
    $('#spn_itisideal').parent().css('left', '268.273px'); 
    $('#spn_isamodern').parent().css('left', '479.727px'); 
    $('#spn_isapopular').parent().css('left', '260.526px'); 
    $('#spn_hasgreatinfrastructure').parent().css('left', '510.974px'); 
} 
+0

bt用这种方法我在打印时遇到了问题。让我知道是否有人找到其他方法。 – Neelam 2013-05-26 15:22:42