highcharts-yAxis网格线的数量不一致

问题描述 投票:0回答:1

有人可以解释为什么在导出的svg中而不是在浏览器版本中yaxis网格线的数量少吗?这是由于保证金更新而发生的吗?如果是这样,为什么还要更新边距,却保留旧的网格线,是否也应该更新?这是我的小提琴http://jsfiddle.net/sabira/r0zvouyp/预先谢谢!

Highcharts.chart('container', {
    chart:{
    events: {
      load: function(){
      const chart = this;
        const {title, yAxis} = chart;
                setRightDy(title);

      const ticks = chart.yAxis[0].ticks;
      let topTick = null;
      for(let tick in ticks){
        if(ticks[tick].isLast)  {
        topTick = tick;
        }
      }
      const tickY = ticks[topTick].label.xy.y;
      const extraMargin = chart.plotTop-tickY + 10;
      const currentMargin = chart.title.alignOptions.margin;

      chart.title.update({
        margin: currentMargin+extraMargin
      }, true, false, false)
      }
    }
  },
    title: {
        align: 'left',
        text: `
        <span class='titleText' style="font-weight: 500; font-size: 12.6px; font-family: Retina; fill:black"> Lorem ipsum dolor sit amet </span><br>
       <span class='dekText' style="font-size: 8.4px; fill: black; font-weight: 300; font-family: Retina"> Integer quis pharetra tellus. Cras tincidunt libero id dignissim convallis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span><br>
<span class='subdekText--strong' style="font-weight: 500; font-size: 8.4px; font-family: Retina; fill:black">Sed aliquam ligula in pretium lobortis.</span>
       <span class='dekText' style="font-size: 8.4px; fill: black; font-weight: 300; font-family: Retina"> Integer quis pharetra tellus. Cras tincidunt libero id dignissim convallis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span><br>
<span class='subdekText--strong' style="font-weight: 500; font-size: 8.4px; font-family: Retina; fill:black">Sed aliquam ligula in pretium lobortis.</span>

        `,
        widthAdjust: -40,
        margin: 20,
    },
    exporting: {
    scale: 1
    },
    yAxis: {
      labels: {
        align: 'left',
        x: 0,
        y: -4
      }
    },
    series: [{
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }],
});

highcharts
1个回答
0
投票

您正在努力解决的问题是,在初始加载后设置新的边距,该边距会更改图表并为其设置动画。但是,导出服务器使用您用来设置但未加载加载回调的选项来呈现新图表,因为这样做没有延迟时间。

为什么不将计算出的边距设置为title.margin对象中的固定值,并设置想要获得的刻度线数量呢?视觉输出是相同的。

演示:https://jsfiddle.net/BlackLabel/owr6f7z2/

  yAxis: {
    labels: {
      align: 'left',
      x: 0,
      y: -4
    },
    tickAmount: 7
  },

API:https://api.highcharts.com/highcharts/yAxis.tickAmount

如果此答案不符合您的要求,请更精确地描述您要实现的目标。

© www.soinside.com 2019 - 2024. All rights reserved.