fusioncharts / fusioncharts-dist

FusionCharts JavaScript Charting library. Over 95+ charts and 1,400+ maps to choose from, with integrations available for all popular JavaScript frameworks & back-end programming languages.
https://www.fusioncharts.com
Other
84 stars 46 forks source link

Not rendering pie2d via plain JavaScript and #14

Closed TheGlobalist closed 3 years ago

TheGlobalist commented 4 years ago

Hi, Since I'm not able to use the angular wrapper (see this issue), I'm trying to switch to the plain JavaScript version for installing FusionCharts. My goal would be to render a pie2d chart.

After importing FusionCharts via its CDN in my index.html


<!-- Step 1 - Include the fusioncharts core library -->
<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
<!-- Step 2 - Include the fusion theme -->
<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script>

And created the following div

<div id="chart-container"></div>

I'm trying to render the chart with the following code

  private chartConfig = {
    type: 'pie2d',
    renderAt: 'chart-container',
    width: '550',
    height: '350',
    dataFormat: 'json',
    dataSource: {
      "chart": {
        "showPercentInTooltip": "0",
        "decimals": "1",
        "useDataPlotColorForLabels": "1",
        //Theme
        "theme": "fusion"
    }
    }
  }

Then, when the component is initialized, I get from my back-end the data that I need and, after, create the chart

  ngOnInit() {
    this.visService.gatheredData.subscribe(res => {
      this.receivingData = res['data']['vis_data'];
      this.chartConfig['dataSource']['data'] = this.receivingData['graduates']['content'];
      FusionCharts.ready(function(){
        var chartObj = new FusionCharts(this.chartConfig);
        chartObj.render('chart-container');
       });
  })
}

Instead of seeing the chart, though, this is what I get

Schermata 2020-08-17 alle 11 58 24

What am I doing wrong? I'm following the examples as provided in the documentation but it seems that something is still wrong

AyanBhadury commented 4 years ago

Hello,

The implementation which you are using is not recommended, FusionCharts have angular-fusioncharts component using which you could render charts in the angular app - https://github.com/fusioncharts/angular-fusioncharts

However, if you are still looking to render charts using the ngOnInit method, kindly let me know the error you are getting at the browser console, I assume that if you include the fusioncharts.charts.js file the error could be resolved.