ECharts - Creating dart js interop for echarts.js

Viewed 374

Trying to convert the starter chart example from Apache Echarts to dart using dart-js-interop to be used in a Flutter web extension. The idea is to be able to have an EChart inside of a flutter web application to utilize Echart's WebGL graphs to render real time plots with millions of points.

Here is the starter tutorial: https://echarts.apache.org/en/tutorial.html#Get%20Started%20with%20ECharts%20in%205%20minutes

Here is the echart.js: https://github.com/apache/incubator-echarts/blob/4.9.0/dist/echarts.js

Never coded in Javascript. I am confused about how to convert this code in the example:

    <script type="text/javascript">
        // based on prepared DOM, initialize echarts instance
        var myChart = echarts.init(document.getElementById('main'));

        // specify chart configuration item and data
        var option = {
            title: {
                text: 'ECharts entry example'
            },
            tooltip: {},
            legend: {
                data:['Sales']
            },
            xAxis: {
                data: ["shirt","cardign","chiffon shirt","pants","heels","socks"]
            },
            yAxis: {},
            series: [{
                name: 'Sales',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };

        // use configuration item and data specified to show chart
        myChart.setOption(option);
    </script>

It looks to call echarts.init but I can not find that in the echarts.js file.

The aim to is create an appropriate Dart equivalent probably looking something like this:

@JS()
library echarts;

import 'package:js/js.dart';

@JS('echarts')
external dynamic init(String divId);
external void setOption(String option);

I can not seem to find any sort of information about how to handle variables returned from functions (in this case it would be var myChart). I also can not find the echart class in the .js file or it's init function.

What am I not understanding about javascript and the dart-js-interop process? Any advice is appreciated.

Best example I have found of process if my description is terrible: Vue.js–Getting started in Dart

0 Answers
Related