[英]highcharts-ng: Equivalent of $('#container').highcharts()
I have created the chart's config in my controller like this: 我已经在控制器中创建了图表的配置,如下所示:
$scope.ohlcChartConfig = {
options: {.......
like the way it is done in HighCharts-ng(angularJS directive of HighCharts). 就像在HighCharts-ng(HighCharts的angularJS指令)中完成的方式一样。
I want the equivalent of the following : 我想要以下内容:
var chart = $('#container').highcharts();
So that I am able to call the following methods in highcharts-ng: 这样我就可以在highcharts-ng中调用以下方法:
var svg = chart.getSVG();
chart.xAxis[0].addPlotBand({...})
chart.xAxis[0].removePlotBand('plot-id');
Currently, I have tried to do it like this: 目前,我已经尝试这样做:
var chart= $scope.ohlcChartConfig;
But when I call the methods, I get the error ' undefined is not a function '. 但是当我调用方法时,出现错误“ 未定义不是函数 ”。
Here is a very simplified JSFiddle where I am trying to get the charts object and call methods on it. 这是一个非常简化的JSFiddle ,我尝试在其中获取图表对象并在其上调用方法。
Thanks in advance. 提前致谢。
Just looked into sources on highcharts-ng
- variable chart
isn't returned anywhere, so you don't have access to methods directly from Highcharts API. 只是查看了highcharts-ng
上的源代码-变量chart
未在任何地方返回,因此您无法直接从Highcharts API中访问方法。
However, you can simply workaround this: 但是,您可以解决此问题:
var chart = Highcharts.charts[0];
Highcharts.charts
array contains all charts on a page. Highcharts.charts
数组包含页面上的所有图表。 See simple demo: http://jsfiddle.net/fxGq4/2/ 观看简单的演示: http : //jsfiddle.net/fxGq4/2/
Note: When using getSVG()
method, created is new chart in a background, so Highcharts.charts
array will get more charts, or undefined
when chart is destroyed. 注意:使用getSVG()
方法时,created是在后台创建的新图表,因此Highcharts.charts
数组将获得更多图表,或者在破坏图表时undefined
。
Also, don't forget to add exporting.js file! 另外,不要忘记添加exporting.js文件! Url: http://code.highcharts.com/exporting.js
. 网址: http://code.highcharts.com/exporting.js
: http://code.highcharts.com/exporting.js
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.