Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use getSVGString() but running into canvas undefined #124

Open
jaimecigna opened this issue Jul 1, 2021 · 0 comments
Open

Trying to use getSVGString() but running into canvas undefined #124

jaimecigna opened this issue Jul 1, 2021 · 0 comments

Comments

@jaimecigna
Copy link

jaimecigna commented Jul 1, 2021

Hello, I am trying to use the getSVGString() but keep getting the following error:

core.js:6456 ERROR TypeError: Cannot read property 'canvas' of undefined
    at e.t.getSVGString (fusioncharts.js:13)
    at ChartComponent.initialized (chart.component.ts:73)
    at ChartComponent_Template_fusioncharts_initialized_0_listener (chart.component.html:2)
    at executeListenerWithErrorHandling (core.js:15285)
    at Object.wrapListenerIn_markDirtyAndPreventDefault [as next] (core.js:15323)
    at Object.next (Subscriber.js:122)
    at SafeSubscriber.Subscriber._next (Subscriber.js:62)
    at SafeSubscriber.Subscriber.next (Subscriber.js:33)
    at EventEmitter_.Subject.next (Subject.js:35)
    at EventEmitter_.emit (core.js:25946)

My Component HTML looks like this:

<fusioncharts (initialized)="initialized($event)" [chartConfig]="chartConfig" [dataSource]="dataSource"></fusioncharts>

My Component TS file looks like this:

import {Component, OnInit} from '@angular/core';
import pptxgen from 'pptxgenjs';
import * as FusionCharts from "fusioncharts";

@Component({
  selector: 'app-chart',
  templateUrl: './chart.component.html',
  styleUrls: ['./chart.component.scss']
})
export class ChartComponent implements OnInit {

  dataSource: any;
  chartConfig: any;

  chart: any;


  constructor() {
    this.chartConfig = {
      id: 'mychart',
      width: '400',
      height: '260',
      type: 'column2d',
      dataFormat: 'json',
    };

    this.dataSource = {
      "chart": {
        "caption": "Countries With Most Oil Reserves [2017-18]",
        "subCaption": "In MMbbl = One Million barrels",
        "xAxisName": "Country",
        "yAxisName": "Reserves (MMbbl)",
        "numberSuffix": "K",
        "theme": "fusion",
      },
      "data": [{
        "label": "Venezuela",
        "value": "290"
      }, {
        "label": "Saudi",
        "value": "260"
      }, {
        "label": "Canada",
        "value": "180"
      }, {
        "label": "Iran",
        "value": "140"
      }, {
        "label": "Russia",
        "value": "115"
      }, {
        "label": "UAE",
        "value": "100"
      }, {
        "label": "US",
        "value": "30"
      }, {
        "label": "China",
        "value": "30"
      }]
    };

  }

  ngOnInit() {

  }

  initialized($event: any){
    this.chart = $event.chart; // Storing the chart instance
    // console.log(this.chart.getSVGString())
    console.log(this.chart);
    console.log(this.chart.getSVGString())
  }


  exportChart(e: any) {
    FusionCharts.batchExport({
      exportFormat: "pdf"
    });
  }

}

Any Ideas on why this is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant