我正在尝试使用python-highcharts包来生成向下钻取的柱状图。我已经在该仓库上运行了drilldown example *,它为我提供了以下代码:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link href="https://www.highcharts.com/highslide/highslide.css" rel="stylesheet" />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/6/highcharts.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/6/highcharts-more.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/6/modules/heatmap.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/6/modules/exporting.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/modules/drilldown.js"></script>
    </head>
    <body style="margin:0;padding:0">
                <div id="container" style="width:850px;height:400px;">Loading....</div>


    <script>
        $(function(){





            Highcharts.setOptions({"global": {}, "lang": {}});
            var option = {"chart": {"renderTo": "container", "width": 850, "height": 400, "type": "column"}, "colors": {}, "credits": {"enabled": false}, "drilldown": {}, "exporting": {}, "labels": {}, "legend": {"enabled": false}, "loading": {}, "navigation": {}, "pane": {}, "plotOptions": {"series": {"borderWidth": 0, "dataLabels": {"enabled": true, "format": "{point.y:.1f}%"}}}, "series": {}, "subtitle": {"text": "Click the columns to view versions. Source: <a href=\"http://netmarketshare.com\">netmarketshare.com</a>."}, "title": {"text": "Browser market shares. January, 2015 to May, 2015"}, "tooltip": {"headerFormat": "<span style=\"font-size:11px\">{series.name}</span><br>", "pointFormat": "<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>"}, "xAxis": {"type": "category"}, "yAxis": {"title": {"text": "Total percent market share"}}};


            var drilldowndata = [{"data": [["v11.0", 24.13], ["v8.0", 17.2], ["v9.0", 8.11], ["v10.0", 5.33], ["v6.0", 1.06], ["v7.0", 0.5]], "type": "column", "name": "Microsoft Internet Explorer", "id": "Microsoft Internet Explorer"}, {"data": [["v40.0", 5], ["v41.0", 4.32], ["v42.0", 3.68], ["v39.0", 2.96], ["v36.0", 2.53], ["v43.0", 1.45], ["v31.0", 1.24], ["v35.0", 0.85], ["v38.0", 0.6], ["v32.0", 0.55], ["v37.0", 0.38], ["v33.0", 0.19], ["v34.0", 0.14], ["v30.0", 0.14]], "type": "column", "name": "Chrome", "id": "Chrome"}, {"data": [["v35", 2.76], ["v36", 2.32], ["v37", 2.31], ["v34", 1.27], ["v38", 1.02], ["v31", 0.33], ["v33", 0.22], ["v32", 0.15]], "type": "column", "name": "Firefox", "id": "Firefox"}, {"data": [["v8.0", 2.56], ["v7.1", 0.77], ["v5.1", 0.42], ["v5.0", 0.3], ["v6.1", 0.29], ["v7.0", 0.26], ["v6.2", 0.17]], "type": "column", "name": "Safari", "id": "Safari"}, {"data": [["v12.x", 0.34], ["v28", 0.24], ["v27", 0.17], ["v29", 0.16]], "type": "column", "name": "Opera", "id": "Opera"}];
            option.drilldown.series = drilldowndata;


            var chart = new Highcharts.Chart(option);

            var data = [{"data": [{"name": "Microsoft Internet Explorer", "y": 56.33, "drilldown": "Microsoft Internet Explorer"}, {"name": "Chrome", "y": 24.030000000000005, "drilldown": "Chrome"}, {"name": "Firefox", "y": 10.38, "drilldown": "Firefox"}, {"name": "Safari", "y": 4.77, "drilldown": "Safari"}, {"name": "Opera", "y": 0.9100000000000001, "drilldown": "Opera"}, {"name": "Proprietary or Undetectable", "y": 0.2, "drilldown": null}], "type": "column", "name": "Brands", "colorByPoint": true}];
            var dataLen = data.length;
            for (var ix = 0; ix < dataLen; ix++) {
                chart.addSeries(data[ix]);
            }









    });
        </script>

    </body>
</html>



在最新的浏览器(最新的Google Chrome)中打开时,会绘制图表,但向下钻取功能不起作用。我看过其他工作示例,例如this one,但无法弄清楚为什么我的代码不起作用。

为什么此代码无法制作正确的明细表,我该如何解决?

*请注意,由于我希望将图表保存在一个文件中,因此我已将Python脚本(H.htmlcontent)的最后一行替换为H.save_file("test_hc")

最佳答案

您有不兼容的模块版本:

<script type="text/javascript" src="https://code.highcharts.com/modules/drilldown.js"></script>


它应该是:

<script type="text/javascript" src="https://code.highcharts.com/6/modules/drilldown.js"></script>




现场演示:http://jsfiddle.net/BlackLabel/6m4e8x0y/4878/

关于javascript - 为什么由python-highcharts制作的此向下钻取图不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60297629/

10-09 14:59