vimalavinisha / angular2-google-chart

Angular 2 google chart
MIT License
59 stars 45 forks source link

How to Set DateFormat #33

Open xzegga opened 7 years ago

xzegga commented 7 years ago

How I can set dateformat to a chart with this library? Reference : https://developers.google.com/chart/interactive/docs/reference#dateformatter

vimalaanthony commented 7 years ago

Hi, Here is the example. Example To draw weight as chart this.ChartData = [["date","weight"],
[new Date(2017, 3, 22,10,10,10), 130 ], [new Date(2017, 3, 21,15,10,20), 170], [new Date(2017, 3, 20), 142], [new Date(2017, 3, 19,8,34,7), 127], [new Date(2017, 3, 18,15,34,7),158], [new Date(2017, 3, 16), 171]] you have to pass this.ChartData to the input of googlechart directive

xzegga commented 7 years ago

sorry @vimalaanthony You misunderstood my question, or I can't explain well, I need set date format for hAxis labels, so far the label is showed like 01/01/2017 but I need to show as "Jan 12, 2017", In angular google chart library for angularjs I can get it with setDateFormatters as an option in chart configuration.

options: {}
formatters: {}
setDateFormat: function (period) {
  switch (period) {
    case 'Days': return 'MMM/dd/yy';
    case 'Weeks': return 'MMM/dd/yy';
    case 'Months': return 'MMM/yyyy';
    case 'Quarters': return 'QQ/yyyy';
    case 'Years': return 'yyyy';
    default: return '';
  }
}