【问题标题】:change highchart data using radio buttons使用单选按钮更改 highchart 数据
【发布时间】:2013-07-02 11:14:58
【问题描述】:

我在我的网站上使用Highcharts 制作了一个图表,它运行成功。

现在我在图表上添加了一个单选按钮,并希望它在我选择单选按钮列表时更改数据。

这是我的工作图表:

   $(function() {

       $('#container1').highcharts({
           chart: {
               type: 'column'
           },

          title: {
           text: 'Information '
           },
            yAxis: {
               title: {
               text: 'data'
        } },


      series: [{

               name: '2011-2012',
               color: '#0000FF',
               data: [1, 0, 4]
     },  {   
              color: '#FF0000',
              name: '2013-2014',
              data: [5, 4, 8]
   }]
       });

   });

</script>

这是我添加的单选按钮:

    <asp:RadioButtonList RepeatDirection="Horizontal" CssClass="radioList" ID="RadioButtonList1"
                AutoPostBack="true" runat="server" RepeatLayout="Flow">
                <asp:ListItem Selected="True" Value="0">data</asp:ListItem>
                <asp:ListItem Value="2">data2</asp:ListItem>
                <asp:ListItem Value="1">data3</asp:ListItem>
            </asp:RadioButtonList>

如何选择单选按钮 data3,然后显示一组新数据?
我最接近的是:

$("#change").click(function(){
if ($("#list").val() == "A")
{
options.series = [{name: 'A', data: [1,2,1]}]
 }
 else
 {
options.series = [{name: 'B', data: [3,2,3]}]
 } 
 var chart = new Highcharts.Chart(options);    
 });

这不起作用,为什么?

【问题讨论】:

    标签: javascript jquery json highcharts


    【解决方案1】:

    如果您只想为图表提供新系列,请使用以下之一:

    【讨论】:

    • Paewel,你不知道我该如何添加额外的东西,例如 yaxis 标题,因为目前它们对于 a、b 和 c 都是一样的。
    • setData一样使用yAxis[0].update( { title: 'new name' });
    【解决方案2】:

    您需要重新计算图表。在他们的 API 中查看 refresh 方法。 您无需创建新实例。 编辑: Here you go!

    EDIT2: 假设你有一个&lt;select&gt;,ID 为list

    $('#list').on('change', function(e){
      if ($(this).val() == 0) {
        chart.series = [{name: 'A', data: [1,2,1]}]
      } else if ($(this).val() == 1) {
        // And so on..
      }
      // Update the chart now that we have modified the series
      chart.redraw();
    });
    

    【讨论】:

    • 我只是把它写出来了。该方法称为redraw,您可以在我提供的链接上找到它:-)
    • 是的,我看过它,问题是,我的使用单选按钮,而示例使用按钮,改变它就是问题所在。该示例打印数据,我需要使用单选按钮显示数据。
    • that's not working iv add it on and it give me an error, "uncaught syntaxerror: unexpected token( $('#list').on('change', function(e){ Uncaught SyntaxError : 意外令牌 ( if ($(this).val() == 0) { chart.series = [{name:
    猜你喜欢
    • 2020-05-17
    • 2015-07-28
    • 2021-06-11
    • 2016-07-08
    • 1970-01-01
    • 2023-04-03
    • 2014-04-15
    • 2021-07-09
    • 1970-01-01
    相关资源
    最近更新 更多