新窗口中的高图 [英] Highchart in new window

查看:20
本文介绍了新窗口中的高图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 highcharts 在我的页面中显示图表.它工作正常,但有时图表中的数据过于浓缩",所以我应该找到一种方法来查看更大尺寸的图表.

I use highcharts to display a chart in my page. It works fine, but some times data in graph is too "condensed" so I should find a way to see the graph in a greater size.

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

I read several posts over internet on this subject: - in general they suggest to use highslide, but i don't want to, as my page is already overlaoded by scripts -somebody tries to pop up the content in a popup, it could fit to me but I didn't succeed - the only quasi-working example which fits to me seems to be the following: (inside the options object I add this properties).

exporting: {
                    buttons: {
                        popUpBtn: {
                            symbol: 'square',
                            _titleKey: 'FullScreenButtonTitle',
                            x: -60,
                            symbolSize:18,
                            symbolFill: '#B5C9DF',
                            hoverSymbolFill: '#779ABF',
                            onclick: function () {
                                var win=window.open('','','location=0,titlebar=0,status=0,width=780,height=350');
                                win.focus();
                                var divtag = win.document.createElement("div");
                                divtag.id = "div1";
                                win.document.body.appendChild(divtag);
                                win.document.write('<script type="text/javascript" src="script/highcharts/js/highcharts.js"></script>
                                                                    <script type="text/javascript" src="script/highcharts/js/modules/exporting.js"></script>');
                                this.options.renderTo=divtag;
                                var chart = new Highcharts.Chart(this.options);

                                win.document.close();
                            }
                        },
                        exportButton: {
                            enabled: true
                        },
                        printButton: {
                            enabled: true
                        }

                    }
                }

但是它不起作用,因为没有插入 div 标签,我得到的就是这个

However it is not working, as the div tag is not inserted and all i get is this

<html>
 <head>
   <script type="text/javascript" src="script/highcharts/js/highcharts.js">  </script>
    <script type="text/javascript" src="script/highcharts/js/modules/exporting.js"></script>
    </head></html>

我无法理解错误.我知道这应该很简单,但我不能一个人出去.

I can't understand the error. I know it should be something simple but I can't get out alone.

--编辑---

我终于明白哪个可能是一个可行的策略:创建一个chartpopup.html"页面,并将构建我可视化的图形副本所需的参数传递给它.

I finally understood which could be a working strategy: create a "chartpopup.html" page, and passing it the parameters needed to build the copy of the graph I visualize.

所以现在我有:

index.html:

index.html:

    chartOptions = {
            series: [
                {
                    name: 'example',
                    data: [83.6, 78.8, 98.5, 93.4, 106.0]
                }]    
          //// CUT SOME CODE

                exporting: {
                    buttons: {
                        popUpBtn: {
                            enabled:true,
                            symbol: 'square',
                            _titleKey: 'FullScreenButtonTitle',
                            x: -60,
                            symbolSize:18,
                            symbolFill: '#B5C9DF',
                            hoverSymbolFill: '#779ABF',
                            onclick: function () {
                                look this!--------> generalPurposeGlobalVar = this;
                                var win=window.open('./chartpopup.html','Full Size Chart','location=0,titlebar=0,status=0,width=780,height=650');

                            }
                        },
                        exportButton: {
                            enabled: true
                        },
                        printButton: {
                            enabled: true
                        }

                    }
                }
            };
        this.highChart=new Highcharts.Chart(this.chartOptions);

和 chartpopup.html:

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

这两个页​​面实际上仅适用于默认图表.如果我修改并重新渲染图表,我将无法在弹出页面上重现它!

This two pages are actually working ONLY with the default graph. If I modify and re-render the graph, I'm not able to reproduce it on the popup page!

我用来修改图表的代码基本上是这样的:

The code I use to modify the graph is basically this:

        this.chartOptions.series=[{name:field.split('_').join('
')}];
        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

推荐答案

在四处问问题后,我发现最好的方法是将包含图表的 div 全屏显示.

After wandering around and asking questions, I found out that the best way to do it is to make fullscreen the div that contains the chart.

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

It's a very simple solution but it works.

这篇文章很有帮助 如何让 div 全屏?

像下面这样的函数应该可以在#graph" div 上实现:

A function like the following should do the trick on a "#graph" div:

function fullscr() {

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

    }

希望对您有所帮助.

这篇关于新窗口中的高图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆