Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VueJs Web Component build #95

Open
ndoulgeridis opened this issue Aug 3, 2021 · 9 comments
Open

VueJs Web Component build #95

ndoulgeridis opened this issue Aug 3, 2021 · 9 comments

Comments

@ndoulgeridis
Copy link

ndoulgeridis commented Aug 3, 2021

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?

@AyanBhadury
Copy link

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

@ndoulgeridis
Copy link
Author

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?

@AyanBhadury
Copy link

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.

@raman-nareika
Copy link

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

@ndoulgeridis
Copy link
Author

No, I migrated to another library

@AyanBhadury
Copy link

@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

@raman-nareika
Copy link

@AyanBhadury we use v3.1.0
image

@AyanBhadury
Copy link

@raman-nareika
Copy link

@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" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants