Flot With “String” x-axis

前端 未结 3 1202
礼貌的吻别
礼貌的吻别 2020-12-24 05:07

When using flot I would like to have a string based x-axis. For example I have a list of customers \"Bob\", \"Chris\", \"Joe\" and would like to plot their revenue on the Y-

3条回答
  •  佛祖请我去吃肉
    2020-12-24 05:51

    You should be able to do this using the tickFormatter option as per this question. I haven't tried it myself, but give this a shot:

    var xAxisLabels = ['Bob', 'Chris', 'Joe'];    
    function xAxisLabelGenerator(x){
        return xAxisLabels[x];
    }
    
    var plot = $.plot($("#placeholder"), { 
        // snip other options...
        xaxis: {
           transform: xAxisLabelGenerator,
           tickFormatter: xAxisLabelGenerator 
        }
    });
    

    This means that the actual x-values should be 0, 1, 2, ...

提交回复
热议问题