How to dynamically change jqplot renderer?

前端 未结 1 1636
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 00:56

Basically, I want the user to be able to change the type of the graph by clicking a drop down menu: BarRenderer, PieRenderer, etc. The data is the same. I know I can call $.jqpl

相关标签:
1条回答
  • 2021-02-10 01:43

    I think the docs are ok, but you will find hidden features inside of it or quirks that aren't documented. IIRC (it's been a while) you will have to call $.jqplot() again but you first need to .empty() your target or you'll get extra / messed up canvases.

    What you really need to do is save your data and allow it to be called later:

    //This isn't real jqplot syntax but it should give you a good idea of what I'm explaining
    
    var charts = [{name:"chart1",renderer:"pie",data:[[1,2],[2,3]]}]
    $('#graph').jqplot(charts[0]);
    
    //later
    charts[0].renderer = "bar";
    $('#graph').empty().jqplot(charts[0]);
    
    0 讨论(0)
提交回复
热议问题