Search code examples
javascriptflotr2

Flotr2 time mode in quarters


I am using Flotr2 with great success. Now we implemented it, with the time mode. Which works like a charm. But now the client wants to show only the quarters (ie 20013-1, 2013-2).

Now Flotr2, auto scales the data to fit the graph. But because no quarter is the same size this fails.

So my question is, is it possible to add quarters in Flotr2 (on the x axis). And if so, is there an example some where in the universe that i did not find?


Solution

  • The best solution is to use the xaxis ticks option, in combination with the tick formatter:

    xaxis: {
      ticks : [],
      tickFormatter: function () {}
    }
    

    Write a function to return an array of quarter start dates, or medians, etc. for your range. They should be in ms.

    The formatter can then output the date format you're looking for as described above.