Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Javascript 新窗口中的海图_Javascript_Backbone.js_Highcharts - Fatal编程技术网

Javascript 新窗口中的海图

Javascript 新窗口中的海图,javascript,backbone.js,highcharts,Javascript,Backbone.js,Highcharts,我使用highcharts在页面中显示图表。 它工作得很好,但有时图形中的数据太“浓缩”,所以我应该找到一种方法来查看更大尺寸的图形 我在网上读了几篇关于这个主题的帖子: -一般来说,他们建议使用highslide,但我不想,因为我的页面已经被脚本覆盖了 -有人试图在弹出窗口中弹出内容,它可能适合我,但我没有成功 -唯一适合我的准工作示例如下: (在options对象中,我添加了此属性) 和chartpopup.html: <!DOCTYPE html> <html

我使用highcharts在页面中显示图表。 它工作得很好,但有时图形中的数据太“浓缩”,所以我应该找到一种方法来查看更大尺寸的图形

我在网上读了几篇关于这个主题的帖子: -一般来说,他们建议使用highslide,但我不想,因为我的页面已经被脚本覆盖了 -有人试图在弹出窗口中弹出内容,它可能适合我,但我没有成功 -唯一适合我的准工作示例如下: (在options对象中,我添加了此属性)

和chartpopup.html:

   <!DOCTYPE html>
   <html>
   <head>
       <meta charset="utf-8">
       <title>Chart full Size</title>
   <script type="text/javascript" src="script/jquery-1.7.1-min.js"></script>
   <script type="text/javascript" src="script/highcharts/js/highcharts.js"></script>
   <script type="text/javascript" src="script/highcharts/js/modules/exporting.js">              </script>

   </head>
   <body>

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

   <script>
   var chart;

   $(document).ready(function() {

       var mychart=window.opener.generalPurposeGlobalVar;

       mychart.options.chart.renderTo= 'container';
       chart = new Highcharts.Chart(mychart.options);


   });
   </script>
   </body>
   </html>

下面是一个使用“oldschool”弹出窗口的Highcharts示例:

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>highcharts foobar</title>
</head>
<body>
    <a href="javascript:open_chart_popup();">Open Chart Popup</a>
<script>
    function open_chart_popup() {
        window.open('popup.html', 'chart popup title', 'width=1680px height=1050px');
    }
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>highcharts foobar</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>

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

<script>
var chart;

$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'line',
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: WorldClimate.com',
            x: -20
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y +'°C';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [{
            name: 'Tokyo',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            name: 'New York',
            data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
        }, {
            name: 'Berlin',
            data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
        }, {
            name: 'London',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
});
</script>
</body>
</html>
本例通过提供一个新的数据数组来使用setData方法。 如果这不符合您的需要,有另一种方法可以刷新您的图表,您可以通过执行
var chart=new Highcharts.chart(选项)重新渲染所有图表。(以上链接对此进行了解释)

这两个链接也是一本不错的读物:

  • (第三和第四部分)

现在,您应该能够根据用户输入对图形执行任何操作。

在四处闲逛并提出问题后,我发现最好的方法是将全屏显示为包含图表的div

这是一个非常简单的解决方案,但它是有效的

这篇文章很有帮助

下面这样的函数应该在“#graph”div上实现这一点:


希望对您有所帮助。

最好的解决方案是针对全屏的HTML5全屏API

function fullScreen(){
     var elem = document.getElementById("highchart_div_id");
    if (elem.requestFullscreen) {
      elem.requestFullscreen();
    } else if (elem.msRequestFullscreen) {
      elem.msRequestFullscreen();
    } else if (elem.mozRequestFullScreen) {
      elem.mozRequestFullScreen();
    } else if (elem.webkitRequestFullscreen) {
      elem.webkitRequestFullscreen();
    }
}
然而,这段代码只适用于新一代浏览器,我有
googlechrome
mozillafirefox


你好

你收到错误消息了吗?嗯,是的,当然,我忘了提到它:
uncaughttypeerror:cannotcallmethod'appendChild'of null
另外,任何其他合适的方法来获得更宽的图形(可能不使用额外的js库)对我来说都是可以接受的,如果您有任何建议…是的,看起来您正在访问弹出窗口中的DOM,然后它才可用。aschuler提供的解决方案将起作用,因为您指向的是现有页面。是的,它将解决您的问题。注意,他正在使用jQuery事件侦听器在document.ready上触发代码。这里的链接解释了jQuery在那个事件中真正在听什么:这是一个确保DOM可以通过javascript访问的好方法。我的问题是,用于填充图表的数据(系列
是从主页的用户输入动态生成的(而不是从服务器获取的)。这就是我不能使用全新页面的原因。我在backbone.js框架中使用colorbox来显示弹出窗口、jquery、jquery ui(很多东西!)(所以我也使用了u.underline.js),页面已经很重了。我想最好的解决方案是动态生成一个页面,显示在新窗口或弹出窗口中。但我在做这件事时遇到了问题。你知道如何动态创建页面内容(包括脚本),然后在新页面/弹出窗口/窗口中呈现它吗?另外:你认为这是一个好策略吗?嗨,阿斯楚勒,第二个选择正是我要做的。多亏了亚历克斯·莫拉莱斯(Alex Morales)的评论,我明白了最好的办法是打开一个现有的页面并处理它的元素。。。这正是我有点结巴的地方。谢谢你的编辑,但我还是不能得到任何结果。请看一下我的编辑。既然你原来的问题得到了回答,你本应该给我奖金的。这真的是一个不同的问题。
        this.chartOptions.series=[{name:field.split('_').join('\n')}];
        this.highChart.destroy();
        this.highChart=new Highcharts.Chart(this.chartOptions);
        this.highChart.xAxis[0].setCategories(_.isEmpty(mygroups) ? [] : mygroups);
        this.highChart.series[0].setData([]);
        this.highChart.setTitle({text: this.highChart.title.text},{text:(field.split('_').join(' ')),  });
        this.highChart.redraw();//
   [...]
        self.highChart.series[0].addPoint(result);//it's a point I calculated before
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>highcharts foobar</title>
</head>
<body>
    <a href="javascript:open_chart_popup();">Open Chart Popup</a>
<script>
    function open_chart_popup() {
        window.open('popup.html', 'chart popup title', 'width=1680px height=1050px');
    }
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>highcharts foobar</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>

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

<script>
var chart;

$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'line',
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: WorldClimate.com',
            x: -20
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y +'°C';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [{
            name: 'Tokyo',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            name: 'New York',
            data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
        }, {
            name: 'Berlin',
            data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
        }, {
            name: 'London',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
});
</script>
</body>
</html>
$('#december_value').bind('keyup', function() {
    var user_input_value = parseFloat($(this).val()); // cast to float

    for (var s in chart.series) { // loop through the series
        var old_data = chart.series[s].data;
        var new_data = [];

        for (var d in old_data ) { // loop through data objects
           new_data.push(old_data[d].config); // config property contains the y value
        }

        new_data[new_data.length - 1] = user_input_value; // update the last value

        chart.series[s].setData(new_data); // use setData method to refresh the datas of the serie
    }
});
function fullscr() {

        $('#graph').css({
            width: $(window).width(),
            height: $(window).height()
        });

    }
function fullScreen(){
     var elem = document.getElementById("highchart_div_id");
    if (elem.requestFullscreen) {
      elem.requestFullscreen();
    } else if (elem.msRequestFullscreen) {
      elem.msRequestFullscreen();
    } else if (elem.mozRequestFullScreen) {
      elem.mozRequestFullScreen();
    } else if (elem.webkitRequestFullscreen) {
      elem.webkitRequestFullscreen();
    }
}