question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wrong context of AxisTickFormatting methods

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior

import { Component, OnInit, Input, OnChanges } from '@angular/core';
import { DatePipe } from '@angular/common';

@Component({
  selector: 'app-value-history',
  template: `
    <ngx-charts-line-chart
      [xAxisTickFormatting]="xAxisTickFormatting"
    </ngx-charts-line-chart>
  `
})
export class ValueHistoryComponent {

   // ...
  constructor(private datePipe: DatePipe) { }

  xAxisTickFormatting(value) {
    return this.datePipe.transform(value, 'short');
  }
}

throws an error:

TypeError: Cannot read property 'transform' of undefined
    at XAxisTicksComponent.webpackJsonp.479.ValueHistoryComponent.xAxisTickFormatting (value-history.component.ts:60)

because the this in the formatting function seems to be the internal xAxisTickComponent

Expected behavior i expect to be able to use the injected datePipe in the AxisTickFormatting function

Reproduction of the problem see example above

What is the motivation / use case for changing the behavior? i want to use angular2 LOCALE_ID to format the date for various countries

Please tell us about your environment: OSX / Webstorm

  • ngx-charts version: 4.2.0
  • Angular version: 4.0.0-rc0 (ng-cli 1.0.0-rc.0)
  • Browser: all
  • Language: Typescript -> es5

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

33reactions
shmarlyacommented, Jun 21, 2018

[xAxisTickFormatting]="xFormat" // in your template guys just simple declare function like this:

 xFormat = (e) => {
   // where e - value of tick by default
   // console.log(this);
   // now you have access to your component variables
   return e + this.someVariable
 }
11reactions
tariknzcommented, May 27, 2018

@rutemja you need to do it in your component: public xAxisTickFormattingFn = this.xAxisTickFormatting.bind(this);

Then just use xAxisTickFormattingFn in your template

Read more comments on GitHub >

github_iconTop Results From Across the Web

swimlane/ngx-charts - Gitter
Hi, I am looking for extend the lib. i am looking to add a funnel chart to begin with but maybe others in...
Read more >
Ngxcharts Only Updating On Hover - ADocLib
Solvedngx charts wrong context of AxisTickFormatting methods i expect to be able to use the injected datePipe in the AxisTickFormatting function.
Read more >
Changelog - ngx-charts - GitBook
Bug: Fixed error being thrown when results is undefined (#217) ... Enhancement: Added x-axis value to the context of a bubble chart tooltip...
Read more >
Source code for dms_tools2.plot
Useful for nice axis-tick formatting. ... Number): isnum = True xlist = [xlist] else: isnum = False formatlist = [] for x in...
Read more >
ng2-charts | Yarn - Package Manager
Access to the .toBase64Image() method #325 ... #656; self.parent.context. ... Adding CHART_DIRECTIVES causes app to error #258; Y Axis Tick Formatting #254 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found