vue-fusioncharts icon indicating copy to clipboard operation
vue-fusioncharts copied to clipboard

VueJs Web Component build

Open ndoulgeridis opened this issue 4 years ago • 9 comments

I am trying to build a chart using VueJS web component:

vue-cli-service build --target wc --inline-vue --name my-app ./src/App.vue --env=production

This command produces the following files on dist:

image

However when I see dist.html on the browser I get:

image

I suspect the problem is with shadow dom:

image

When it tries to get the element to render the chart it fails due to shadow dom VueJS WC build produces.

When run yarn serve app is working fine but does not produce shadow DOM:

image

Do you think shadow DOM bugs fusion charts? Is there a workaround? Do I miss something there?

ndoulgeridis avatar Aug 03 '21 23:08 ndoulgeridis

@ndoulgeridis FusionCharts needs a container to render the charts, since it's not getting the container hence the error is showing.

AyanBhadury avatar Aug 04 '21 07:08 AyanBhadury

There is a container but when I build using --target wc it creates a shadow-root and this container is part of shadow dom

image

I think this causes the problem then on render because the container with ID fc-2 cannot be found normally because it's part of Shadow DOM and not a normal element.

If I run for example yarn serve I see the same HTML structure but without shadow-root and it works fine.

image

So what I understand is fusion charts are not compatible when you try to render them in an element that is part of shadow dom.

Is there a workaround?

ndoulgeridis avatar Aug 04 '21 08:08 ndoulgeridis

not that I can think of immediately, if you are looking for server-side rendering you can check out FusionExport, for FusionCharts make sure the dom node is present where the chart will render.

AyanBhadury avatar Aug 04 '21 08:08 AyanBhadury

hi, faced the same issue: fusioncharts can't find the container within shadow dom. @ndoulgeridis any solutions?

raman-nareika avatar Jan 06 '22 15:01 raman-nareika

No, I migrated to another library

ndoulgeridis avatar Jan 06 '22 20:01 ndoulgeridis

@raman-nareika which version by vue are you using if its vue2 use vue-fusioncharts 3.1.0 If you are using vue3 use vue-fusioncharts 3.2.0

AyanBhadury avatar Jan 07 '22 02:01 AyanBhadury

@AyanBhadury we use v3.1.0 image

raman-nareika avatar Jan 10 '22 09:01 raman-nareika

@raman-nareika Working Demo. : https://codesandbox.io/s/multi-level-pie-9q48h?file=/src/App.vue

AyanBhadury avatar Jan 10 '22 10:01 AyanBhadury

@ndoulgeridis found a solution:

FusionChart.vue

<template>
  <div id="chart-container"></div>
</template>
<script>
export default {
  props: {
    chartType: {
      type: String,
      required: true
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "400"
    },
    dataSource: {
      type: Object,
      required: true
    }
  },
  data: () => ({
    dataFormat: "json"
  }),
  mounted() {
    this.render();
  },
  methods: {
    render() {
      const fusionChart = new FusionCharts({
        type: this.chartType,
        width: this.width,
        height: this.height
      });

      fusionChart.setJSONData(this.dataSource);
      fusionChart.render(this.$root.$el.querySelector("#chart-container"));
    }
  }
};
</script>

So, you can use the component above and inject dataSource via props, e.g. <FusionChart chart-type="doughnut2d" :data-source="dataSource" />

raman-nareika avatar Jan 11 '22 13:01 raman-nareika