0

My line chart shows wrong date format for the X-axis label. It is showing /Date(1425148200000)/, but I want it to show as dd/MM/yyyy.

This is my code:

.CategoryAxis(axis => axis.Categories(model => model.Price.EffectiveDate))
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
Suk
  • 53
  • 9

1 Answers1

0

I handled this in the client side (javascript).

In client code, you need to instance a Date object passing this value 1425148200000 to the constructor, like:

var x = new Date(1425148200000)

here's what x will look like afterwards:

Sat Feb 28 2015 20:30:00 GMT+0200 (Jerusalem Standard Time)

Then you just need to format it as you wish. (you can use the following date object methods to return a string in a DD/MM/YYYY format:

x.getDate()  // returns 28
x.getMonth() // returns 1
x.getFullYear()  // returns 2015 

Alternatively, you may opt to display a string field in the grid, instead of the date value itself, which value would be the return of "toShortDateString()" on your DateTime object.

Veverke
  • 9,208
  • 4
  • 51
  • 95
  • So, I called a javascript function using '.Template' as .CategoryAxis(axis => axis .Categories(model => model.Price.MedispanEffectiveDate) .Labels(labels=>labels.Template("#=dateFuntion(Price.MedispanEffectiveDate)#"))) and in script part as function dateFuntion(date) { var date = new Date(parseInt(date.substr(6))); return date; }... Still not working... – Suk Mar 20 '15 at 11:02
  • Ok... I changed my code in backend...Used `ToShortDateString()`. So, returning Price.MedispanEffectiveDate.ToShortDateString(); (string)... Thanx Veverke.. – Suk Mar 21 '15 at 07:11