Search code examples
angularjstypescriptngx-charts

compering two years with ngx-charts


struggling with that few houres now -trying to compare sellings of a company of two years(2015,2016) - the problem is that I can not sort it with Date beacuse then ofcourse 2016 will come after 2015 -and I want them to 'overlapping' I fixed that issue with that:

let d = new Date(null,deilyResults[i].date.month - 1, deilyResults[i].date.day);

-so I set 'year' to null -but that automaticly change year to "1900" which result in incorrect data in tooltip: enter image description here

what is the correct way to do that in this case ?


Solution

  • Set the year of the data the same (ether 2016 or 2015), and than use ng-template to show just the month and day of the date (or combine series (year) and just the month and the day from name) in the tooltip like this (you need ngx-charts at least version 5.3.0):

    <ngx-charts-line-chart
    ...>
        <ng-template #tooltipTemplate let-model="model">
            <h6>{{model.series}} - {{model.name|date:'yyyy'}}.{{model.name|date:'mm.dd'}}</h6>
            <h4>{{model.value}}</h4>
        </ng-template>
    </ngx-charts-line-chart>