how to draw multiple bar charts grouped by category with flot js

懵懂的女人 提交于 2019-12-10 11:14:57

问题


I'm using flot library to display a bar charts and I need to group by certain value in this way:

|
|          +----+        +----+    
|          |    |        |    |    
|          |    |        |    |    
|          |    |        |    |    
| +----+   |    |        |    |    
| |    |   |    |        |    |    
| |    |   |    |        |    |    
| |    |   |    |        |    |    
|-+----+---+----+--------+----+----
   val 1    val2          val3
    category #1        category #2

Thanks Sergey G. for the Ascii :)

I have the variables d1, d2, d3 to the values ​​of the bars 1, 2 and 3 respectively (sorted by category). The question is: How do I add the category below ticks? Sorry for my bad "Google-Translator" English and thank you very much!

Code:

$.plot(
    $("#placeholder"),
    [

            {
        label: labelChart,
        data: d1,
        color: '#92d5ea',
        bars: {
            show: true,
            barWidth: 0.5,
            align: "center",
            order:2
        },   

       multiplebars:true  
    },
    {
        label: labelChart,
        data: d2,
        color: '#92d5ea',
        bars: {
            show: true,
            barWidth: 0.5,
            align: "center",
            order:3
        },   

       multiplebars:true  
    },
    {
        label: labelChart,
        data: d3,
        color: '#92d5ea',
        bars: {
            show: true,
            barWidth: 0.5,
            align: "center",
            order:3
        },   

       multiplebars:true  
    }


    ],
    {
        xaxis: {
            ticks: ticksData
        }, 

        yaxis: { 
            min:0
        }
    }
);

回答1:


Use the categories plugin, as demonstrated in this example.



来源:https://stackoverflow.com/questions/15031217/how-to-draw-multiple-bar-charts-grouped-by-category-with-flot-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!