我有一个问题,改变它们为高图.我创建了一个数组来保存所有主题,并尝试通过select事件更改它们.
- var highcharts_theme = [];
- /* Default theme */
- highcharts_theme.push({});
- /* Dark Blue theme */
- highcharts_theme.push({
- colors: ["#DDDF0D","#55BF3B","#DF5353","#7798BF","#aaeeee","#ff0066","#eeaaee","#aaeeee"],chart: {
- backgroundColor: {
- linearGradient: [0,250,500],stops: [
- [0,'rgb(48,48,96)'],[1,'rgb(0,0)']
- ]
- },.... Shortened for brevity.....
- $('#theme-type').selectmenu({ width: 200 }).change(function (e) {
- var themeIndex = parseInt($('#theme-type').val());
- Highcharts.theme = highcharts_theme[themeIndex];
- // Apply the theme
- highchartsOptions = Highcharts.setOptions(Highcharts.theme);
- });
我所遇到的问题是,如果我转向Skies主题,那么这是很好的,但随后改为任何其他主题,天空背景与主题的其他元素一起保持.
谢谢
解决方法
每当你设置一个主题时,它会与现有的主题相融合,因此任何选项都不会出现在新的主题中,它将从现有的主题中挑选出来.这可能不总是需要.
不幸的是,Highcharts没有提供返回在第一次加载时设置的默认值的选项.以下代码可用于获取该功能
- // Make a copy of the defaults,call this line before any other setOptions call
- var HCDefaults = $.extend(true,{},Highcharts.getOptions(),{});
- function ResetOptions() {
- // Fortunately,Highcharts returns the reference to defaultOptions itself
- // We can manipulate this and delete all the properties
- var defaultOptions = Highcharts.getOptions();
- for (var prop in defaultOptions) {
- if (typeof defaultOptions[prop] !== 'function') delete defaultOptions[prop];
- }
- // Fall back to the defaults that we captured initially,this resets the theme
- Highcharts.setOptions(HCDefaults);
- }