2012-09-05 150 views

回答

2

如果您想在繪製繪圖後更改它,只需對元素本身執行操作即可。

// find me the tspan containing the specified text and change it to... 
$("tspan:contains('Total fruit consumption')").text("Something New") 
+0

可能無法通過瀏覽器,尤其因爲其根據的假設,SVG將被渲染,而是基於瀏覽器highchart可能會或可能不會吐出SVG –

1

Highchart不提供任何方法來動態地更新標籤頭爲Highcharts 3.0:使用jQuery選擇器,因爲它是那麼容易。 儘管它確實提供了一種動態更新系列的方法:http://api.highcharts.com/highstock#Series.update()

要更新標籤標頭,我們需要遵循暴力方法,即在更新圖表選項後再次渲染圖表。下面的代碼應該做的伎倆:

var mychart = $('#container').highcharts(); 
    mychart.options.labels.items[0].html= "Changed label header"; 
    mychart = new Highcharts.Chart(mychart.options); 
    mychart.render(); 

的jsfiddle:http://jsfiddle.net/msjaiswal/ZD4N5/2/

類似的線程:here

9

使用標籤,你可以使用渲染文本(),然後使用變量來保持物體的insted的。如果您需要動態更新此文本,則只需使用attr()函數和update。

http://jsfiddle.net/6GKCJ/2/

var title = chart.renderer.text('Total fruits consumption', 100, 90) 
     .css({ 
      fontSize: '12px' 
     }) 
     .add(); 

     $('#btn').click(function(){ 

      title.attr({ 
       text:'newText' 
      }); 
     }); 
+0

這就是我正在尋找因爲,感謝提到這一點。 –