【问题标题】:How can I add a <path> element in a <g> element in Highcharts如何在 Highcharts 的 <g> 元素中添加 <path> 元素
【发布时间】:2014-09-03 15:55:56
【问题描述】:

我想在我的图表/svg 中添加这些元素:

<g
   transform="matrix(1.25,0,0,-1.25,175.4,27)">
  <path
     d="M 0,0 -4.252,-11.338 -4.252,0 0,0 z"
     style="fill:#711f1c;fill-opacity:1;fill-rule:nonzero;stroke:none"
     />
</g>

我已经使用了渲染器(在 chart &gt; event &gt; load 中):

window.chart_myid = new Highcharts.Chart({
 chart: {
  events : {
   load : function(){
     this.renderer.g("myshape")
     .attr({
         "transform" : "matrix(1.25,0,0,-1.25,175.4,27)"
        })
     .add();

     this.renderer.path(['M', 0, 0, 'L', -4.252, -11.338, -4.252, 0, 0, 0, 'z'])
    .css({
        'fill' : '#711f1c',
        'fill-opacity' : '1',
        'fill-rule' : 'nonzero',
        'stroke' : 'none'
    })
    .add("myshape");
   }
  }
 }

结果是:

<g class="highcharts-myshape" 
   transform="matrix(1.25,0,0,-1.25,175.4,27)"/>
<path 
   fill="none" 
   d="M 0 0 L -4.252 -11.338 -4.252 0 0 0 z" 
   style="fill:#711f1c;fill-opacity:1;fill-rule:nonzero;stroke:none;"
/>

如何将&lt;path&gt; 元素添加到&lt;g&gt; 元素中?

【问题讨论】:

    标签: javascript jquery svg highcharts


    【解决方案1】:

    您需要将 g 元素而不是其名称传递给 add 即

     var g = this.renderer.g("myshape")
     .attr({
         "transform" : "matrix(1.25,0,0,-1.25,175.4,27)"
        })
     .add();
    
     this.renderer.path(['M', 0, 0, 'L', -4.252, -11.338, -4.252, 0, 0, 0, 'z'])
    .css({
        'fill' : '#711f1c',
        'fill-opacity' : '1',
        'fill-rule' : 'nonzero',
        'stroke' : 'none'
    })
    .add(g);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-04
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多