Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从JSFIDLE导出Highcharts代码_Jquery_Highcharts - Fatal编程技术网

Jquery 从JSFIDLE导出Highcharts代码

Jquery 从JSFIDLE导出Highcharts代码,jquery,highcharts,Jquery,Highcharts,我需要将Highcharts的代码从JSFIDLE导出到本地文件。以下是JSFIDLE上的图表代码: 它在JSFIDLE上运行得很好,但当我将其放入本地文件并在浏览器中打开时,图表不会显示出来。我使用“视图框架源代码”从JSFIDLE获得代码,下面是我得到的: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UT

我需要将Highcharts的代码从JSFIDLE导出到本地文件。以下是JSFIDLE上的图表代码: 它在JSFIDLE上运行得很好,但当我将其放入本地文件并在浏览器中打开时,图表不会显示出来。我使用“视图框架源代码”从JSFIDLE获得代码,下面是我得到的:

    <!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="robots" content="noindex, nofollow">
  <meta name="googlebot" content="noindex, nofollow">

  <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>

    <link rel="stylesheet" type="text/css" href="/css/result-light.css">


  <style type="text/css">

  </style>

  <title></title>


<script type='text/javascript'>//<![CDATA[

$(function () {
    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=usdeur.json&callback=?', function (data) {

        var startDate = new Date(data[data.length - 1][0]), // Get year of last data point
            minRate = 1,
            maxRate = 0,
            startPeriod,
            date,
            rate,
            index;

        startDate.setMonth(startDate.getMonth() - 3); // a quarter of a year before last data point
        startPeriod = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());

        for (index = data.length - 1; index >= 0; index = index - 1) {
            date = data[index][0]; // data[i][0] is date
            rate = data[index][1]; // data[i][1] is exchange rate
            if (date < startPeriod) {
                break; // stop measuring highs and lows
            }
            if (rate > maxRate) {
                maxRate = rate;
            }
            if (rate < minRate) {
                minRate = rate;
            }
        }

        // Create the chart
        $('#container').highcharts('StockChart', {

            rangeSelector: {
                selected: 1
            },

            title: {
                text: 'USD to EUR exchange rate'
            },

            yAxis: {
                title: {
                    text: 'Exchange rate'
                },
                plotLines: [{
                    value: minRate,
                    color: 'green',
                    dashStyle: 'shortdash',
                    width: 2,
                    label: {
                        text: 'Last quarter minimum'
                    }
                }, {
                    value: maxRate,
                    color: 'red',
                    dashStyle: 'shortdash',
                    width: 2,
                    label: {
                        text: 'Last quarter maximum'
                    }
                }]
            },

            series: [{
                name: 'USD to EUR',
                data: data,
                tooltip: {
                    valueDecimals: 4
                }
            }]
        });
    });
});
//]]> 

</script>


</head>

<body>
  <script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>


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

</body>

</html>

//= 0; 索引=索引-1){
日期=数据[index][0];//数据[i][0]是日期
汇率=数据[index][1];//数据[i][1]是汇率
如果(日期<开始周期){
中断;//停止测量高点和低点
}
如果(速率>最大速率){
最大速率=速率;
}
如果(速率<最小速率){
minRate=速率;
}
}
//创建图表
$(“#容器”).highcharts('StockChart'{
范围选择器:{
选定:1
},
标题:{
文字:“美元兑欧元汇率”
},
亚克斯:{
标题:{
文字:“汇率”
},
绘图线:[{
值:minRate,
颜色:“绿色”,
短跑风格:“短跑”,
宽度:2,
标签:{
文本:“上季度最低限额”
}
}, {
值:maxRate,
颜色:“红色”,
短跑风格:“短跑”,
宽度:2,
标签:{
文本:“上一季度最大值”
}
}]
},
系列:[{
名称:“美元兑欧元”,
数据:数据,
工具提示:{
数值小数:4
}
}]
});
});
});
//]]> 

所以它只显示空白页。我怎样才能修好它?谢谢。

添加到头部后,它可以在局部正常工作。不知道为什么,但它解决了问题。

可能是试图打开文件,而不是在服务器上运行。无法在
文件://
协议中使用ajax。您的代码文件是从Highcharts网站加载的(根据OP代码),所以应该不会有问题@您能告诉我们您在JS控制台中是否有任何错误吗?