[英]highcharts, highstock without jQuery
I understand you can use: 我了解您可以使用:
$(element).highcharts("StockChart", {})
to get a chart on that element. $(element).highcharts("StockChart", {})
获得该元素的图表。
However, I'd like to either be able to get gold of the highchart
object so I can manipulate it afterwards, or I'd like to do: 但是,我希望能够获得highchart
对象的黄金,以便以后可以对其进行操作,或者我想这样做:
new Highcharts.Chart({
chart : {
renderTo : 'container'
type : 'StockChart'
}
...
});
Firstly : The latter does not work for type 'StockChart'. 首先 :后者不适用于“股票图表”类型。 I get error code 17 which says: 我收到错误代码17 ,其中指出:
"The requested series type does not exist" “所请求的系列类型不存在”
Secondly : I'd prefer to set the renderTo
option to an element rather than an id . 其次 :我更愿意将renderTo
选项设置为元素而不是id 。 By using an id it forces my element to also use an id, but where I can have a container and a subelement
in it, it becomes hard to reference that. 通过使用id,它会强制我的元素也使用id,但是在可以包含容器和subelement
的地方,很难引用它。
Now , if you have many graphs on a single html page, id's are not ideal. 现在 ,如果您在单个html页面上有很多图形,则id是不理想的。 Rather I would like to use the actual dom element to pass. 而是我想使用实际的dom元素来传递。
By using $(element).highcharts("StockChart", {})
I was able to set almost all other options as global ones, including the rangeSelector
and get things to work. 通过使用$(element).highcharts("StockChart", {})
我几乎可以将所有其他选项设置为全局选项,包括rangeSelector
并使其正常工作。
However, I still need to be able to access this
, which is available in event functions, such as load, so I guess I could set a global one, but that might be a bit overkill. 但是,我仍然需要能够访问this
,该函数在事件函数(例如load)中可用,因此我想我可以设置一个全局函数,但这可能有点过头了。
I see three questions in your case: 在您的情况下,我看到三个问题:
1) To get object when creating chart, you have two ways: 1)要在创建图表时获取对象,有两种方法:
with jQuery: 使用jQuery:
var chart = $(element).highcharts('StockChart', options).highcharts();
without jQuery: 没有jQuery:
var chart = new Highcharts.StockChart(options);
2) Error #17: 2)错误#17:
"The requested series type does not exist" “所请求的系列类型不存在”
Is caused by type : 'StockChart'
. 由type : 'StockChart'
引起type : 'StockChart'
。 type
is reserved for a series type. type
为系列类型保留。 As @Raeen Hashemi said, to create Highstock, use different constructor: new Highcharts.StockChart(options)
. 正如@Raeen Hashemi所说,要创建Highstock,请使用其他构造函数: new Highcharts.StockChart(options)
。
3) Yes, you can pass an object to renderTo
: http://jsfiddle.net/yvxwa6oq/ 3)是的,您可以将一个对象传递给renderTo
: http : //jsfiddle.net/yvxwa6oq/
new Highcharts.StockChart({
chart: {
renderTo: document.getElementsByClassName("container")[0]
},
series: [{
name: 'USD to EUR',
data: [10, 20]
}]
});
4) this
- honestly, I'm not sure why you need access to this
somewhere else than event handlers. 4) this
-老实说,我不确定为什么您需要在事件处理程序之外的其他地方访问this
。 Instead use Highcharts.charts[index]
or stored variables like chart
or $(element).highcharts()
而是使用Highcharts.charts[index]
或诸如chart
或$(element).highcharts()
类的存储变量
for ES6, use it in below method. 对于ES6,请按以下方法使用。
import * as Highcharts from "highcharts";
import * as highchartsTree from 'highcharts/modules/treemap';
also, any highchart type can be added instead of treemap 另外,可以添加任何高图类型而不是树形图
highchartsTree(Highcharts);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.