【问题标题】:HighCharts: loading from csv file, blank page in HTML/JSHighCharts:从 csv 文件加载,HTML/JS 中的空白页
【发布时间】:2016-11-09 21:15:46
【问题描述】:

我在下面有以下 HTML/JS(取自 Highcharts 示例),旨在从 CSV 文件加载一些基本数据。但是在加载 .htm 时,它只是空白。

我尝试过各种方法,例如在 IE 中使用 F12 来查看控制台;没有错误。如果我查看源代码,我可以正确地看到应有的 HTML。但是页面只是空白。如果我使用 IE 的 Debugger 并在 .get() 行上放置一个断点,Step Into 似乎会跳到结束 get 括号的底部?

CSV 文件与 .htm 位于同一文件夹中,数据如下:

 DateTime,Count
    10/11/2016 00:00:00,20
    10/12/2016 00:00:00,12
    10/13/2016 00:00:00,5

我确认文件末尾没有空行。

HTML/JS:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <style type="text/css">
${demo.css}
        </style>
        <script type="text/javascript">
   $(document).ready(function() {
    // Get the CSV and create the chart
    $.get('count_changes.csv', function (data) {

        $('#container').highcharts({

            data: {
                csv: csv
            },

            title: {
                text: 'Daily visits at www.highcharts.com'
            },

            subtitle: {
                text: 'Source: Google Analytics'
            },

            xAxis: {
                tickInterval: 7 * 24 * 3600 * 1000, // one week
                tickWidth: 0,
                gridLineWidth: 1,
                labels: {
                    align: 'left',
                    x: 3,
                    y: -3
                }
            },

            yAxis: [{ // left y axis
                title: {
                    text: null
                },
                labels: {
                    align: 'left',
                    x: 3,
                    y: 16,
                    format: '{value:.,0f}'
                },
                showFirstLabel: false
            }, { // right y axis
                linkedTo: 0,
                gridLineWidth: 0,
                opposite: true,
                title: {
                    text: null
                },
                labels: {
                    align: 'right',
                    x: -3,
                    y: 16,
                    format: '{value:.,0f}'
                },
                showFirstLabel: false
            }],

            legend: {
                align: 'left',
                verticalAlign: 'top',
                y: 20,
                floating: true,
                borderWidth: 0
            },

            tooltip: {
                shared: true,
                crosshairs: true
            },

            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function (e) {
                                hs.htmlExpand(null, {
                                    pageOrigin: {
                                        x: e.pageX || e.clientX,
                                        y: e.pageY || e.clientY
                                    },
                                    headingText: this.series.name,
                                    maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
                                        this.y + ' visits',
                                    width: 200
                                });
                            }
                        }
                    },
                    marker: {
                        lineWidth: 1
                    }
                }
            },

            series: [{
                name: 'All visits',
                lineWidth: 4,
                marker: {
                    radius: 4
                }
            }, {
                name: 'New visitors'
            }]
        });
    });

});
        </script>
    </head>
    <body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<!-- Additional files for the Highslide popup effect -->
<script src="https://www.highcharts.com/samples/static/highslide-full.min.js"></script>
<script src="https://www.highcharts.com/samples/static/highslide.config.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="https://www.highcharts.com/samples/static/highslide.css" />

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

    </body>
</html>

【问题讨论】:

  • 我看不到你在哪里给你的系列提供数据。
  • @bassxzero 这取自一个工作示例。那么我错过了什么?我在示例中也没有看到类似的内容。
  • 将 $.get('count_changes.csv', 函数(数据))更改为 $.get('count_changes.csv', 函数 (csv)
  • @bassxzero 我之前也尝试过。结果相同。

标签: javascript jquery html csv highcharts


【解决方案1】:

发现了这个:

您需要一个服务器,因为您无法在 file:// URL 上发出 XMLHttpRequests

uploading external csv file to highcharts not working

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多