简体   繁体   English

选择框(下拉列表)以加载主题脚本

[英]select box (dropdown list) to load theme script

i'm using highchart and want to use a select list for loading themes. 我正在使用highchart,并希望使用选择列表来加载主题。 the theme are .js files. 主题是.js文件。 i want to acheave something like that: 我想做这样的事情:

<select id="theme">
<option value="">Default</option>
<option value="js/theme/theme1.js">theme1</option>
<option value="js/theme/theme2.js">theme2</option>
</select>

in other words, how can i change the src="" tag of the <script></script> in the head of my html using select box!! 换句话说,如何使用选择框更改html头中<script></script>src=""标签!

thank you!! 谢谢!!

If you want to give option of different themes to your users you need to include all highchart theme js scripts in your html. 如果要为用户提供不同主题的选项,则需要在HTML中包含所有highchart主题js脚本。 All highcharts theme js files do this: 所有highcharts主题js文件都这样做:

Highcharts.theme = {
colors: ["#DDDF0D", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
"#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],....
....
var highchartsOptions = Highcharts.setOptions(Highcharts.theme);

so when you include a js file, it changes the theme of the highcharts. 因此,当您包含一个js文件时,它将更改highcharts的主题。

You can edit these theme js files and change the names of the settings as Highcharts.themeDarkBlue = { ..... , Highcharts.themeLightBlue = { ..... , etc. Then when your user makes a selection from the drop down you need to call whatever theme the user has selected as 您可以编辑这些主题js文件,并将设置的名称更改为Highcharts.themeDarkBlue = { .....Highcharts.themeLightBlue = { .....等。然后,当用户从下拉列表中进行选择时您需要调用用户选择的任何主题

Highcharts.setOptions(Highcharts.themeDarkBlue);

and re-populate the chart. 并重新填充图表。

Update: 更新:

Can't really generate a fiddle for this so: 真的不能为此产生小提琴:

Your html: 您的html:

.....
    <script src='themes/themeDarkBlue.js'></script>
    <script src='themes/themeLightBlue.js'></script>
    <script src='themes/themeBlack.js'></script>
.... //more theme references

In your themes folder you have three js files, themeDarkBlue.js, themeLightBlue.js and themeBlack.js themes文件夹中,您有三个js文件,themeDarkBlue.js,themeLightBlue.js和themeBlack.js

Your themeDarkBlue.js content: 您的themeDarkBlue.js内容:

var darkBlueTheme = {colors: ["#DDDF0D", "#55BF3B", "#DF5353", "#7798B"....};

Your themeLightBlue.js content: 您的themeLightBlue.js内容:

var lightBlueTheme = {colors: ["#xxxF0D", "#xxxF3B", "#DF5353", "#7798B"....};

Inside your html: 在您的html中:

$("#themeDropDown").change(function(){
   if ($(this).val() = 'Dark Blue'){
      Hightcharts.setOptions(darkBlueTheme);
   }
   else if ($(this).val() = 'Light Blue'){
      Hightcharts.setOptions(lightBlueTheme);
   }
   //else if 'Black'
   repopulateHighChart();
});

This should be clear enough. 这应该足够清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM