当尝试显示图表时,出现Highcharts.js脚本错误

smtd7mpg  于 9个月前  发布在  Highcharts
关注(0)|答案(1)|浏览(86)

我试图在我的本地anaconda jueyter笔记本(windows 10机器)中复制一个highchart的演示,当试图显示图表时,它抛出了一个Highcharts.js脚本加载错误。
这是Demo代码:

from highcharts_core.chart import Chart
from highcharts_core.options import HighchartsOptions
from highcharts_core.options.plot_options import PlotOptions
from highcharts_core.options.axes.x_axis import XAxis
from highcharts_core.options.axes.y_axis import YAxis
from highcharts_core.options.axes.accessibility import AxisAccessibility
from highcharts_core.options.axes.title import AxisTitle
from highcharts_core.options.title import Title
from highcharts_core.options.subtitle import Subtitle
from highcharts_core.options.legend import Legend
from highcharts_core.options.plot_options.series import SeriesOptions
from highcharts_core.options.series.area import LineSeries
from highcharts_core.options.series.labels import SeriesLabel
from highcharts_core.options.responsive import Responsive, ResponsiveRules, Condition
from highcharts_core.constants import EnforcedNull

chart_options = HighchartsOptions(
    title = Title(text = 'U.S Solar Employment Growth by Job Category, 2010-2020',
                  align = 'left'),
    subtitle = Subtitle(text = 'Source: <a href="https://irecusa.org/programs/solar-jobs-census/" target="_blank">IREC</a>',
                        align = 'left'),
    y_axis = YAxis(title = AxisTitle(text = 'Number of Employees')),
    x_axis = XAxis(
        accessibility = AxisAccessibility(range_description = 'Range: 2010 to 2020')
    ),
    legend = Legend(layout = 'vertical',
                    align = 'right',
                    vertical_align = 'middle'),
    plot_options = PlotOptions(series = SeriesOptions(point_start = 2010,
                                                      label = SeriesLabel(connector_allowed = False)))
)

override_options = HighchartsOptions(legend = Legend(layout = 'horizontal',
                                                     align = 'center',
                                                     vertical_align = 'bottom'))
responsive_config = Responsive(
    rules = [
        ResponsiveRules(chart_options = override_options,
                        condition = Condition(max_width = 500))
    ]
)
chart_options.responsive = responsive_config

series1 = LineSeries(name = 'Installation & Developers',
                     data = [43934, 48656, 65165, 81827, 112143, 142383, 171533, 165174, 155157, 161454, 154610])
series2 = LineSeries(name = 'Manufacturing',
                     data = [24916, 37941, 29742, 29851, 32490, 30282, 38121, 36885, 33726, 34243, 31050])
series3 = LineSeries(name = 'Sales & Distribution',
                     data = [11744, 30000, 16005, 19771, 20185, 24377, 32147, 30912, 29243, 29213, 25663])
series4 = LineSeries(name = 'Operations & Maintenance',
                     data = [EnforcedNull, EnforcedNull, EnforcedNull, EnforcedNull, EnforcedNull, EnforcedNull, EnforcedNull, EnforcedNull, 11164, 11218, 10077])
series5 = LineSeries(name = 'Other',
                     data = [21908, 5548, 8105, 11248, 8989, 11816, 18274, 17300, 13053, 11906, 10073])

chart_options.add_series(series1, series2, series3, series4, series5)

chart = Chart.from_options(chart_options)
chart.display()

下面是显示的错误,

Something went wrong with the Highcharts.js script. It should have been automatically loaded, but it did not load for over 5 seconds. Check your internet connection, and then if the problem persists please reach out for support. (You can also check your browser's console log for more details.)

Detailed Error Message:
Highcharts is not defined

下面是我使用的版本,python - 3.10.13

  1. Highcharts-core 1.3.7
  2. IPython 8.16.0
  3. ipykernel 6.25.2
  4. jupyter_client 8.3.1
  5. jupyter_client 8.3.1
    我确实尝试过清除单元格输出,也重新启动内核等,但没有喜悦!基本上,我尝试了这个stackoverflow问题中指定的解决方案-Highcharts for Python doesn't render in Jupyter
    提前感谢!
x7yiwoj4

x7yiwoj41#

根据与OP在评论中的讨论,我们确定:
1.此问题发生在浏览器中的xmlyterNotebook中。
1.此问题 * 不是 * 在浏览器中的xmlyterLab中发生。
1.我们排除了网络连接问题。
基于此,这似乎是一个与v.1.4.0之前版本中的bug in Highcharts Core for Python相关的问题,其中Xueyter Notebook包括RequireJS,而Xueyter Lab不包括。
此错误与浏览器中发生的JavaScript代码之间的冲突有关,该代码是Highcharts for Python生成的,用于在notebook和RequireJS中呈现可视化(特别是加载所需的Highcharts JS脚本)。
PR#112中已经修复了这个错误,它已经是Highcharts Core for Python v.1.4.0的候选版本的一部分,并将于2023年10月4日或5日发布。发布后,此特定问题应在升级到最新版本后解决。

相关问题