jQWidgets Forums
jQuery UI Widgets › Forums › ASP .NET MVC › Chart X-Axis Date Format Issue
Tagged: MVC chart Date Format
This topic contains 1 reply, has 2 voices, and was last updated by Martin 6 years, 12 months ago.
-
Author
-
Hi,
I’m trying to follow a sample found in the community to format my Chart x-axis label.
I want to display 3 letter month.My DataAdapter.Records display all Date Records correctly.
dataAdapter.records (13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 0 : {month: "0001-01-01T00:00:00", smsCount: 0} 1 : {month: "2017-05-01T00:00:00", smsCount: 0} 2 : {month: "2017-06-01T00:00:00", smsCount: 0} 3 : {month: "2017-07-01T00:00:00", smsCount: 0} 4 : {month: "2017-08-01T00:00:00", smsCount: 679} 5 : {month: "2017-09-01T00:00:00", smsCount: 1020} 6 : {month: "2017-10-01T00:00:00", smsCount: 0} 7 : {month: "2017-11-01T00:00:00", smsCount: 0} 8 : {month: "2017-12-01T00:00:00", smsCount: 0} 9 : {month: "2018-01-01T00:00:00", smsCount: 0} 10 : {month: "2018-02-01T00:00:00", smsCount: 0} 11 : {month: "2018-03-01T00:00:00", smsCount: 0} 12 : {month: "2018-04-01T00:00:00", smsCount: 0} length : 13 __proto__ : Array(0)
The chart settings:
const settings = { source: dataAdapter.records, categoryAxis: { type: 'date', baseUnit: 'month', dataField: 'month', formatFunction: function (dateValue) { // var mDate = (monthvalue.getDate().toString() + '-' + monthvalue.getMonth().toString() +'-'+ monthvalue.getFullYear().toString()); var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; console.log(dateValue + '|' + months[new Date(dateValue).getMonth()]); return months[new Date(dateValue).getMonth()]; } } };
When I receive the value in debugger, the dateValue is completly wrong like if the Date Format is wrong.
Second records:
dateValue Mon May 01 0834 00:00:00 GMT+0200 (W. Europe Daylight Time)
Third item:
dateValue Mon May 01 0834 00:00:00 GMT+0200 (W. Europe Daylight Time)
I don’t what to do to change it ?
Any help ?
ThanksHello vRITHNER,
I created a Demo with your example.
The wrong value of the date was coming because of your first value: {month: “0001-01-01T00:00:00”, smsCount: 0}.
The year is 0001 and it cannot format it correctly. It fixed when I removed this record.Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.