jQuery Highcharts:使用下拉列表更改图表类型 [英] jQuery Highcharts: change chart type using dropdown list

查看:130
本文介绍了jQuery Highcharts:使用下拉列表更改图表类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改图表的值,如下所示

i'm trying to change the value of chart as following

<!doctype html>
<head>
<script>
var chart1; // globally available

$(document).ready(function() {
    var chart = 'pie'
    $("select").change(function(){
        chart = $('#chart').val();
        alert(chart);
    });

   chart1 = new Highcharts.Chart({
       chart: {
          renderTo: 'container',
          type: chart 
        },
        yAxis: {
           title: {
              text: 'Temprature'
           }
        },
        series: [{
           name: 'mach_1',
            data: [<?php 
            foreach($chart as $`row) {
            echo  $row['temp'].",";
            }
           ?>]
          }]
      });
});
</script>
</head>

<body>
  <div id="form">

    <label>Select a chart : </label>
    <select id="chart">
      <option>pie</option>
      <option>column</option>
    </select>

  </div>

  <div id="container"></div>

</body>
</html>

我知道这会改变select上的图表值,但它不会改变图表本身。有什么想法吗?

i know this will change the value of chart on select, but it doesn't change the chart itself. Any ideas?

推荐答案


  1. 您的原始问题很难阅读和解释; stackoverflow的一些代码编辑器标签与您尝试发布的代码交织在一起。将来,将您的代码示例放在 jsfiddle 上可能会有所帮助。

如果我正确理解了这个问题,那么您正在寻找更改所显示图表的类型。显示数据的饼图;现在显示数据的条形图;现在显示折线图等。

If I'm understanding the question correctly, you are looking to change the type of chart displayed. Show a pie chart of the data; now show a bar graph of the data; now show a line chart, etc.

如果您有Highcharts问题,那么在Highcharts论坛之前,其他人已经问过这个问题是一个不错的选择。在您的情况下,我认为这是真的:动态更改图表类型? - http: //highslide.com/forum/viewtopic.php?f=9&t=5501&p=26274&hilit=switch+chart+types#p26274

When you have a Highcharts question, it's a good bet someone else has asked that question before on the Highcharts forum. In your case, I think this is true: "Change chart type dynamically?" - http://highslide.com/forum/viewtopic.php?f=9&t=5501&p=26274&hilit=switch+chart+types#p26274

在上面链接的Highcharts论坛问题中,Highcharts的作者Torstein Honsi回答了这个问题,并且包括一个你可能会发现有用的起点,因为他正在改变它的图表类型。 http://jsfiddle.net/tccpT/ 稍后,Highcharts支持团队成员包括我们看到的小提琴另一个更改图表类型的示例。 http://jsfiddle.net/2hLr5/

In the Highcharts forum question linked above, Highcharts author Torstein Honsi answers the question and includes a fiddle you may find to be a useful starting point, as he's changing the chart type in it. http://jsfiddle.net/tccpT/ Later on, a Highcharts support team member includes a fiddle where we see another example of changing the chart type. http://jsfiddle.net/2hLr5/

当饼图涉及两个以上的数据时,通常建议不要使用饼图作为可视化数据的方法。饼图具有的值越多,感知这些数据之间的关系就越困难。

When a pie chart involves more than two pieces of data, it is generally advisable to not use a pie chart as a means of visualizing data. The more values a pie chart has, the more difficult it becomes to perceive the relationships between those pieces of data.

这篇关于jQuery Highcharts:使用下拉列表更改图表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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