2012-12-03 20 views
2
<script> 
    $(function() { 


     var chart = new Highcharts.Chart({ 
      chart: { 
       renderTo: 'container', 
       type: 'funnel', 
       marginRight: 100 
      }, 
      title: { 
       text: 'Sales funnel' 
      }, 
      plotArea: { 
       shadow: null, 
       borderWidth: null, 
       backgroundColor: null 
      }, 
      plotOptions: { 
       series: { 
        dataLabels: { 
         enabled: true, 
         format: '<b>{point.name}</b> ({point.y:,.0f})', 
         color: 'black', 
         softConnector: true 
        }, 
        neckWidth: '30%', 
        neckHeight: '25%' 

        //-- Other available options 
        // height: pixels or percent 
        // width: pixels or percent 
       } 
      }, 
      legend: { 
       enabled: false 
      }, 
      series: [{ 
       name: 'Unique users', 
       data: [ 
        ['Website visits', 15654], 
        ['Downloads',  4064], 
        ['Requested price list', 1987], 
        ['Invoice sent', 976], 
        ['Finalized', 846] 
       ] 
      }] 
     }); 

     // Add the jQuery UI resizin 
     var container = $('#container')[0]; 
     $('#resizer').resizable({ 
      // On resize, set the chart size to that of the 
      // resizer minus padding. If your chart has a lot of data or other 
      // content, the redrawing might be slow. In that case, we recommend 
      // that you use the 'stop' event instead of 'resize'. 
      resize: function() { 
       chart.setSize(
        this.offsetWidth - 20, 
        this.offsetHeight - 20, 
        false 
       ); 
      } 
     }); 
    });​ 
    </script> 

我使用highcharts做了一个样本漏斗图,所以我不想使用highcharts导出功能。我需要使用div id来获取下图的svg。
下面的代码是图表的div部分,它将呈现这个div中的图表。 如何使用div id获取highcharts的svg?

<div id="container" style="height: 400px;"> 
    </div> 



    using div id "container" i need to get svg of the chart. 

回答

3

有一个叫getSVG方法可以,如果你有你的chart实例中使用。

var svg = chart.getSVG();

参考

+0

如果有人得到一个错误,因为Highcharts没有getSVG功能,你可能错过了[导出模块](http://www.highcharts.com/docs/export-module/export-module-overview)。 –

0

你可以把它简单的使用$( '#集装箱.highcharts容器')HTML()。

这会给整个svg作为字符串,你可以玩。

你也可以得到延长highcharts出口JS和使用下面的函数

http://api.highcharts.com/highcharts#Chart.getSVG()