ZoeHime
ZoeHime

Reputation: 33

How to display month name in x axis of JQPlot

Here's my data example:
Hi, I'm using JQPlot for the first time and got stuck with displaying month name in x axis.

var s1 = [[1, 782751.00], [2, 112592.00], [3, 1350924.00], [4, 648777.00], [5, 725266.00], [6, 358824.00]]

var s2 = [[1, 16], [2, 20], [3, 22], [4, 20], [5, 21], [6, 10]]

var ticks = [1,2,3,4,5,6,7,8]

Here, 1,2,3...etc indicates serial number of month (as in 1 for jan,2 for feb...)

Currently it's showing these numbers...but I need to display it as jan,feb,mar,apr and so on..

I've tried DATEPART(MONTH,CreatedDate) AS value and CONVERT(char(3), CreatedDate, 0) in query but then the graph doesn't show up...a little help will be much appreciated.


seems like it was quite simple :| :)

Made changes to get

var ticks = ['January','February','March','April','May'......] 

query:

 SET DATEFORMAT DMY; 
                        SELECT value FROM
                        ( 
                        SELECT  DISTINCT CONVERT(char(3), CreatedDate, 100) as value,DATEPART(MONTH,CreatedDate) AS Sl
                        FROM SER_TB_JobInfo
                        WHERE CreatedDate BETWEEN DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0) AND GETDATE() ) A ORDER BY Sl

Upvotes: 1

Views: 1153

Answers (1)

AnthonyLeGovic
AnthonyLeGovic

Reputation: 2335

You can do translation on javascript side using some kind of "int to month" translator :

//Ticks you actually have
var ticks = [1,2,3,4,5,6,7,8];
//Translator array to do conversion from integer to month
var translator = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for(var i = 0; i < ticks.length; ++i){
 ticks[i] = translator[i];   
}

Ticks is now containing ["January", "February", "March", "April", "May", "June", "July", "August"]

Upvotes: 1

Related Questions