Having problems with jqPlot bar chart

前端 未结 3 1950
星月不相逢
星月不相逢 2021-02-20 04:16

I\'m using jqPlot to create a bar graph, but I ran into a few problems.

Problem 1: The first and last bars on the graph are cut off. Only half of it is

3条回答
  •  抹茶落季
    2021-02-20 04:56

    Here is a simple hack that I used to show a margin.

    I create a starting date and an ending date which are respectively one day before and one day after the contents I want to show.

    For example if I want to show the month of January 2012

    var startingDate = new Date(2012, 0, 0); //=> 31th Dec 2011
    var endingDate = new Date(2012, 1, 1); //=> 1st Feb 2012
    

    Then I declare my own DateTickFormatter where I will not printout these two dates.

    $.jqplot.DateTickFormatter = function(format, val) {
            if (!format) {
                format = '%Y/%m/%d';
            }
    
            if(val==startingDate.getTime() || val==endingDate.getTime()){
                return "";
            }else{
                return $.jsDate.strftime(val, format);
            }
        };
    

    Then in the xaxis I put the following options:

    xaxis : {
          renderer:$.jqplot.DateAxisRenderer, 
          min:startingDate,
          max:endingDate,
          tickInterval:'1 day'
    }
    

提交回复
热议问题