简体   繁体   English

工具提示中的图表未完全呈现

[英]A chart in the tooltip is not being fully rendered

I generate a tooltip with a chart on it. 我生成一个带有图表的工具提示。

tooltip: {
    borderRadius: 15,
    borderWidth: 0,
    shadow: false,
    enabled: true,
    backgroundColor: 'none',
    useHTML: true,
    shared: true,
    formatter: function() {
        var div = document.createElement('div');

        Highcharts.chart(div, {
            chart: {
                height: 300,
                width: 300
            },
            title: {
                text: 'Title'
            },
            series: [
                {
                    data: [10, 20],
                    color: 'red'
                },
                {
                    data: [20, 10],
                    color: 'green'
                }
            ],
            yAxis: {
                title: {
                    text: 'Quantity'
                }
            }
        });

        return div.innerHTML;
    }
}

Real data example 真实数据示例

The main chart is of the line type. 主图表为line The tooltip chart is of the column type. 工具提示图表为column类型。

在此处输入图片说明

Dummy data example 虚拟数据示例

The main chart is of the line type. 主图表为line The tooltip chart is of the line type as well. 工具提示图也属于line You may see half-visible red and green symbols. 您可能会看到半可见的红色和绿色符号。 They are either hidden by something (I am trying to figure out what it is) or were suddenly stopped being rendered (I highly doubt it). 它们要么被某种东西隐藏(我试图弄清楚它是什么),要么突然停止渲染(我对此表示高度怀疑)。

在此处输入图片说明

Do you have any ideas what it could be? 您有什么想法吗?

Update 1 更新1

I was able to identify the element the series are rendered into. 我能够确定该系列渲染到的元素。 It's there, the size seems correct, it has points rendered. 在那里,大小似乎正确,已经渲染了点。

 <g class="highcharts-series-group" data-z-index="3">...</g>

Though, I couldn't bring it to the front, or make it visible by any CSS means. 不过,我无法将其放在最前面,也无法通过任何CSS手段使其可见。

在此处输入图片说明

That's basically the question. 基本上这就是问题。 How to bring it to the forward or unhide? 如何使其前进或后退?

Update 2 更新2

I was experimenting with setting the dimensions by both 我正在尝试同时设置尺寸

div.style.width = "500px";

and

chart: {
    height: 300,
    width: 300
}

to no avail. 无济于事。

Update 3 更新3

I created a jsfiddle. 我创建了一个jsfiddle。 Please, have a look. 请看一看。

Do you have any ideas? 你有什么想法? Any thought would be invaluable. 任何想法都是无价的。

The solution to this issue is quite simple. 解决此问题的方法非常简单。 In the formatter callback function you are returning an innerHTML of a div with a created chart. 在格式化程序回调函数中,您将返回带有已创建图表的div的innerHTML。 However, this is not the interactive chart but only HTML. 但是,这不是交互式图表,而只是HTML。

The chart plot area is hidden because of the animation. 图表图区域由于动画而被隐藏。 Disable it and you will see plotted series: 禁用它,您将看到绘制的系列:

plotOptions: {
  series: {
    animation: false
  }
}

Demo: 演示:


Another solution is to return an HTML div element in the tooltip formatter and then create a chart inside the div using setTimeout. 另一个解决方案是在工具提示格式化程序中返回HTML div元素,然后使用setTimeout在div内创建图表。 With this approach the animation is working fine. 通过这种方法,动画效果很好。

Code: 码:

formatter: function() {

  setTimeout(function() {
    Highcharts.chart('tooltip', {
      chart: {
        width: 200,
        height: 200,
        type: 'column'
      },
      title: {
        text: 'Title'
      },
      credits: {
        enabled: false
      },
      series: [{
        data: [50, 75],
        color: 'red',
        selected: true
      }, {
        data: [10, 100],
        color: 'green'
      }],
      yAxis: {
        title: {
          text: 'Quantity'
        }
      }
    });
  }, 0);

  return '<div id="tooltip"></div>';
}

Demo: 演示:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM