Jump to content
JChartFX Community
  • 0

Documentation for setCustomFormat date masks?



4 answers to this question

Recommended Posts

  • 0

Assuming this data and function to extract week number, note that I have no idea if this function implements the week number that you expect as week numbering seems to be vaguely defined


var items = [

{ "Date": "2016-07-06T08:45:10.280Z", "Value": 15},
{ "Date": "2016-08-15T12:15:00.000Z", "Value": 12},
{ "Date": "2016-08-25T23:45:10.280Z", "Value": 18},

function getWeekOfYear(date)

    var target = new Date(date.valueOf()), dayNumber = (date.getUTCDay() + 6) % 7, firstThursday;
    target.setUTCDate(target.getUTCDate() - dayNumber + 3);
    firstThursday = target.valueOf();
    target.setUTCMonth(0, 1);
    if (target.getUTCDay() !== 4)
        target.setUTCMonth(0, 1 + ((4 - target.getUTCDay()) + 7) % 7);
    return Math.ceil((firstThursday - target) /  (7 * 24 * 3600 * 1000)) + 1;

I see 3 choices,


1) If you are creating a bar chart or even if using a line/area chart you do not have holes in your data or do not want to plot holes in the data, you could add a field with the week number using the date and then tell jChartFX that you want to use that as the label, e.g.


for(var i = 0; i < items.length; i++) {

    var item = items;
    item["Week"] = getWeekOfYear(new Date(Date.parse(item["Date"])));
var fieldMap;
fieldMap = new cfx.FieldMap();
fieldMap = new cfx.FieldMap();
2) If you are creating a line/area chart and want to have holes in the display for missing weeks, just do the same as before but use cfx.FieldMap.XValue for the week field.
3) It is also possible to keep using the date field as the labels or X value and handle an event so that you can return a string used for the X axis labels, this would be a little more involved but I thought I should mention it in case it is useful in other scenarios.
Link to comment
Share on other sites

  • 0

Unfortunately we do not support week number.


d -> Day

dd -> Day with trailing zero if necessary

ddd- >Day of Week Abbreviated

dddd -> Day of Week

M -> Month

MM -> Month with trailing zero if necessary

MMM -> Month Name Abbreviated

MMMM -> Month Name

yy -> Last 2 digits of year

yyyy -> Year

h -> Hour

hh -> Hour with trailing zero

H -> Hour (24 hour format)

HH -> Hour (24 hour format) with trailing zero

m -> Minute

mm -> Minute with trailing zero

s -> Second

ss -> Second with trailing zero

t -> First letter of am/pm

tt -> am/pm





Link to comment
Share on other sites

  • 0

Thanks for your reply,


case 1) is the one that is usually requested, maybe with the null handling variation of case 2).


Week of year definition is indeed a bit complicated, need to make sure that corner cases of 53 weeks in a year + position of week number 1 of a year are supported correctly.




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...