【问题标题】:Apex Charts dont resize properly when using Flexbox使用 Flexbox 时 Apex 图表无法正确调整大小
【发布时间】:2019-03-24 18:04:30
【问题描述】:

最近我将 Floats 更改为 FlexBox,以便更轻松地使用面板(正如我在其他问题上所建议的那样)。虽然大多数事情都按我的预期工作,但在更改后我遇到了 Apex Charts 的问题。

完整代码在这里: https://github.com/EvotecIT/PSWriteHTML/blob/master/Examples/Example12-Charts/Example12.html

这是加载时的外观。您会注意到,在第一行和第二行图表中,即使它们所在的面板就位并且它适用于第一行,它们也会超出范围。

如果我调整大小(比如 1 毫米),它将开始正常工作。

知道可能是什么问题吗?

在顶点图表 CSS 中,它具有不使用溢出的 cmets(我尝试过,但它没有做任何事情)但老实说,我什至忘记附加该 CSS 并且没有任何改变(就像所有事情都是由 JS.

        .apexcharts-canvas {
            position: relative;
            user-select: none;
            /* cannot give overflow: hidden as it will crop tooltips which overflow outside chart area */
        }

        /* scrollbar is not visible by default for the legend, hence forcing the visibility */

请记住,我在 JS/CSS/HTML 方面完全是个菜鸟,所以请原谅我的语言。

【问题讨论】:

  • 您需要提供minimal reproducible example,因为我们无法通过您的所有代码进行调试和图像解析。
  • github上附有完整的HTML(检查)
  • 不够好,一个可重现的样本应该在问题范围内。
  • 这是负责上图的 HTML。可重现。你不需要任何其他东西来运行它。这是一个包含所有内容的静态 1 HTML 文件。您只需将该粘贴复制到您机器上的 .html 中即可。
  • 你错过了我的观点。这不是如何发布问题。如果有什么不清楚的地方,请重读How to Ask

标签: javascript html css apexcharts


【解决方案1】:

您需要将所有脚本移到末尾而不是注入 HTML 以允许 SVG 文档解析器正确获取元素的大小。

工作Codepen Example

var options = {
  "chart": {
    "height": 350,
    "type": "line",
    "toolbar": {
      "show": true,
      "tools": {
        "download": true,
        "selection": true,
        "zoom": true,
        "zoomin": true,
        "zoomout": true,
        "pan": true,
        "reset": true
      },
      "autoSelected": "zoom"
    }
  },
  "plotOptions": {
    "bar": {
      "horizontal": true
    }
  },
  "dataLabels": {
    "enabled": true,
    "offsetX": -6,
    "style": {
      "fontSize": "12px",
      "colors": [
        null
      ]
    }
  },
  "series": [{
      "name": "People count",
      "data": [
        400,
        430,
        448
      ]
    },
    {
      "name": "People death",
      "data": [
        450,
        0,
        200
      ]
    }
  ],
  "xaxis": {
    "type": "category",
    "categories": [
      "2015",
      "2016",
      "2017"
    ]
  },
  "stroke": {
    "show": true,
    "curve": "straight",
    "width": 2,
    "colors": [
      "#0000ff",
      "#008000"
    ]
  },
  "legend": {
    "position": "right",
    "offsetY": 100,
    "height": 230
  },
  "title": {

  }
}

var chart = new ApexCharts(document.querySelector('#ChartID-2rhiatbe'),
  options
);
chart.render();

【讨论】:

  • 哇!谢谢你。没想到 :-) 我将使用我现在拥有的东西,当它得到修复时,它会自行修复。谢谢你。
  • 我实际上是在写一个对此的回应,github.com/apexcharts/apexcharts.js/issues/330 似乎是最近修补的类似问题。有没有可能补丁没有按预期工作?
  • @OliverDunk 是的,很可能补丁不起作用。也许我错过了一些测试。
  • @junedchhipa 没有难过的感觉,感谢您的快速回复:)
  • 缩放/平移工具目前仅适用于日期时间序列。因此,您不会在类别 x 轴图表中看到它们。
猜你喜欢
  • 2020-04-03
  • 2021-11-09
  • 1970-01-01
  • 1970-01-01
  • 2019-05-06
  • 1970-01-01
  • 2012-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多