Highcharts的Python接口

fdx2calv  于 2023-04-21  发布在  Highcharts
关注(0)|答案(1)|浏览(166)

当Highcharts的Python接口在本周发布时,我非常高兴。现在我正在努力将它集成到Web页面中。
按照这个例子https://core-docs.highchartspython.com/en/latest/#generate-the-javascript-code-for-your-chart,我试图将生成的Java脚本文件集成到我的Web页面中,如下所示:

<html>
<head>
  <title>Tescht</title>
</head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<body>
  <script src="./my_target_file.js"></script>
</body>
</html>

但它不起作用。

nwwlzxa7

nwwlzxa71#

我找到解决办法了!
我的问题的答案可以在这里找到:
https://ahumbleopinion.com/highcharts-tips-accessing-chart-object-from-container-id/
对容器ID的引用是mssing。我的代码现在看起来像这样:

<!DOCTYPE html>
<html>
   <head>
      <title>Highcharts Tutorial</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script src = "https://code.highcharts.com/highcharts.js"></script>
   </head>
   
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
      <script src = "./my_target_file.js"></script>   
   </body>
</html>

在Java Script文件中,容器的引用方式如下:

// my_target_file.js
document.addEventListener('DOMContentLoaded', function() {
new Highcharts.chart("container",
{
...
},
);
});

现在图表已呈现!

相关问题