ecastanie
ecastanie

Reputation: 65

How to use javascript library amCharts with Dart?

I want to draw graphs from amCharts library in Dart.

I transformed a code example from amCharts website in Dart following guidelines described here https://www.dartlang.org/articles/js-dart-interop/ but I can not get a chart to be drawn.

I am using Dart editor on mac os.

Everything runs fine when I run the dart app but the chart does not appear.

Does anobydy already tried to use amCharts with Dart?

Upvotes: 3

Views: 1129

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76353

Here is a dart version of the Js code of Simple pie chart.

import 'dart:js';

main(){
  final chartData = /* same datas as JS */;
  context['AmCharts'].callMethod('ready', [(){
    final chart = new JsObject(context['AmCharts']['AmPieChart']);
    chart['dataProvider'] = new JsObject.jsify(chartData);
    chart['titleField'] = "country";
    chart['valueField'] = "litres";
    chart['outlineColor'] = "#FFFFFF";
    chart['outlineAlpha'] = 0.8;
    chart['outlineThickness'] = 2;
    chart['balloonText'] = "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>";

    // WRITE
    chart.callMethod('write', ["chartdiv"]);
  }]);
}

Basically :

Upvotes: 5

Related Questions