为什么pythonhighcharts制作的向下搜索图不起作用?

2024-04-23 12:22:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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")


Tags: textnamehttpssrccomiddatavar
1条回答
网友
1楼 · 发布于 2024-04-23 12:22:54

您的模块版本不兼容:

<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/

相关问题 更多 >