timopu Posted July 6, 2016 Report Share Posted July 6, 2016 Hello, where can I find list of supported date masks for setCustomFormat? Specifically I'm looking for week number mask. br, Timo Quote Link to comment Share on other sites More sharing options...
0 JuanC Posted July 7, 2016 Report Share Posted July 7, 2016 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.setName("Week"); fieldMap.setUsage(cfx.FieldUsage.Label); chart1.getDataSourceSettings().getFields().add(fieldMap); fieldMap = new cfx.FieldMap(); fieldMap.setName("Value"); fieldMap.setUsage(cfx.FieldUsage.Value); chart1.getDataSourceSettings().getFields().add(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. JuanC Quote Link to comment Share on other sites More sharing options...
0 JuanC Posted July 6, 2016 Report Share Posted July 6, 2016 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 Regards, JuanC Quote Link to comment Share on other sites More sharing options...
0 timopu Posted July 7, 2016 Author Report Share Posted July 7, 2016 Unfortunately we do not support week number. Hello again JuanC, week number support would be appreciated! Not super critical, but I have some cases where, for example, production data is represented per week. br, Timo Quote Link to comment Share on other sites More sharing options...
0 timopu Posted August 2, 2016 Author Report Share Posted August 2, 2016 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. br, Timo Quote Link to comment Share on other sites More sharing options...
Question
timopu
Hello,
where can I find list of supported date masks for setCustomFormat? Specifically I'm looking for week number mask.
br,
Timo
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
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.