最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Building a d3.js widget in flutter - Stack Overflow

programmeradmin1浏览0评论

I'm getting started with flutter and trying build a Stateful Widget, which when called would display a d3.js chart. My thinking is to build a chart into a stateful widget and use the changenotifier provider to update the chart data, and d3.js has beautiful plots.

I've found a couple of other references of other people doing similar things...

Dart js interop with D3

How to embed a D3 chart in a Polymer.dart element?.

It seems to make sense that if I already had an element in my html code that I could reference from my dart code I could attach to that, and create my plot - as in the latter reference...

import 'dart:js' as js;
js.context['d3'].callMethod('select', [shadowRoot.querySelector('.chart')]);

What I don't understand, is how I would be able to create that .chart element in the DOM within my stateful widget itself so that from the perspective of my dart code, it sees it as just a dart widget.

Put another way, what is it than I can select that is local to the widget itself so that I can nest the resulting widget in other widgets?

Is wanting to wrap the d3.js in a stateful widget in dart something that could be acplished in a relatively encapsulated way? And is trying to create the html within the widget itself a good approach?

I'm getting started with flutter and trying build a Stateful Widget, which when called would display a d3.js chart. My thinking is to build a chart into a stateful widget and use the changenotifier provider to update the chart data, and d3.js has beautiful plots.

I've found a couple of other references of other people doing similar things...

Dart js interop with D3

How to embed a D3 chart in a Polymer.dart element?.

It seems to make sense that if I already had an element in my html code that I could reference from my dart code I could attach to that, and create my plot - as in the latter reference...

import 'dart:js' as js;
js.context['d3'].callMethod('select', [shadowRoot.querySelector('.chart')]);

What I don't understand, is how I would be able to create that .chart element in the DOM within my stateful widget itself so that from the perspective of my dart code, it sees it as just a dart widget.

Put another way, what is it than I can select that is local to the widget itself so that I can nest the resulting widget in other widgets?

Is wanting to wrap the d3.js in a stateful widget in dart something that could be acplished in a relatively encapsulated way? And is trying to create the html within the widget itself a good approach?

Share Improve this question edited Jul 22, 2020 at 2:57 Flaminator asked Jul 22, 2020 at 2:41 FlaminatorFlaminator 5847 silver badges17 bronze badges 2
  • 1 Hey Flaminator, could you find any solution? – Abbas Jafari Commented Nov 7, 2020 at 11:44
  • Unfortunately no I didn't. I ended up using vue.js instead of flutter for the project as a result. – Flaminator Commented Nov 29, 2020 at 23:50
Add a ment  | 

2 Answers 2

Reset to default 2

I guess the best you could do is to use flutter_webview_plugin and run javascript code (for example, draw d3.js chart) inside this webview.

https://pub.dev/packages/plotly_js was web patible only when posting. An actual port would be nice.

发布评论

评论列表(0)

  1. 暂无评论