Ngx-charts: Black chart on safari. Gradient dosnt work

Created on 11 Dec 2017  Â·  21Comments  Â·  Source: swimlane/ngx-charts

[ x ] bug report
[ ] feature request
[ ] support request

On safari browser chart is black. All works fine , but color is black.
When i change [gradient]="true" to false is ok but without gradient 👎

  lineChartColorScheme = {
    domain: ['#C40536', '#6d6d6d']
  }

Angular 5.0.0
"d3": "^4.12.0",

Most helpful comment

Also looking for a fix here.

All 21 comments

some ideas ?

any solutions?

@KamilKmitaLasoft how did you resolve this?

i didnt :(

Same issue here

This issue es because you have to pass the absolute route of the linearGradient in Safari

Back in version 3.1.0 they were using this approach :

https://github.com/swimlane/ngx-charts/blob/9b79199e909b0c4ea8959891fe63fa2835c2fb20/src/area-chart/area-chart.component.ts#L209

      let pageUrl = window.location.href;
      this.clipPathId = 'clip' + id().toString();
      this.clipPath = `url(${pageUrl}#${this.clipPathId})`;

But now i cant figure out how they're passing the "base ref" to the charts

Now theyre using a variable called : gradientUrl but cant figure out how they link the base ref there.

If anyone has a solution here that would be awesome. Love the gradient but the problem with it rendering on Safari and mobile is tough.

Also looking for a fix here.

Agreed. A fix here would be most valuable.

Following...

This may potentially be the same issue as #1062 where the gradient works just fine unless the xaxis and yaxis properties are BOTH set to false. Setting either of them to true brings the gradient back but of course this isn't desired behavior. (Seems to be occurring on Chrome as well)

This happens on Safari, and iOS Devices.

Nobody found a workaround?

Lol... still no gradient.

Any updates?

Anybody found a way to solve this issue?

Hello this is my workaround for the problem, when i load my chart or change the data I just update gradient with a little delay :

@ViewChild(AreaChartComponent, { static: true }) chart: AreaChartComponent;

public ngAfterViewInit() {

        setTimeout(() => {
            this.chart.gradient = true;
            this.chart.update();
        }, 10);
    }

Hope this will solve your issue.

Hi @Drake62610

Please share how did you get the reference of the Chart?

Thanks

This issue es because you have to pass the absolute route of the linearGradient in Safari

Back in version 3.1.0 they were using this approach :

https://github.com/swimlane/ngx-charts/blob/9b79199e909b0c4ea8959891fe63fa2835c2fb20/src/area-chart/area-chart.component.ts#L209

      let pageUrl = window.location.href;
      this.clipPathId = 'clip' + id().toString();
      this.clipPath = `url(${pageUrl}#${this.clipPathId})`;

But now i cant figure out how they're passing the "base ref" to the charts

Now theyre using a variable called : gradientUrl but cant figure out how they link the base ref there.

This is the reason why gradient doesn't work in safari. Safari needs to take absolute path.
Workaround:

Option 1: Use HashLocationStrategy for angular route
RouterModule.forRoot(routes, { useHash: true }

Option 2: Keep using PathLocationStrategy but append current url to fill: url(#id) after view initialized

ngAfterViewInit() {
    this.updateGradient();
    // New path will be rendered on resize
    window.onresize = () => {
      this.updateGradient();
    }
  }

  updateGradient() {
    setTimeout(_ => {
      const areas = document.querySelectorAll('path.area');
      areas.forEach(area => {
        const fill = area.getAttribute('fill');
        const id = fill.match(/#.+/)[0];
        area.setAttribute('fill', `url(${window.location.href + id}`);
      });
    }, 200);
  }

We have published a mirrored version ngx-charts that should fix this issue via @bugsplat/ngx-charts and opened PR #1637

Was this page helpful?
0 / 5 - 0 ratings