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

layout prop is ignored #8

Closed
nboughton opened this issue Sep 27, 2019 · 10 comments
Closed

layout prop is ignored #8

nboughton opened this issue Sep 27, 2019 · 10 comments

Comments

@nboughton
Copy link

I'm trying to create a stacked bar chart but find that the layout prop is being ignored. My .vue file can be seen here

The relevant line invokes plotly with:

<plotly :data="qData.freqDist" :layout="layout.freq" />

The relevant data is defined as:

 data() {
    return {
      ...
      qData: {},
      layout: {
        freq: {
          title: "Draw Frequency",
          barmode: "stack"
        }
      },
     ...
  }

The qData prop is filled via ajax request at page load and after a form action is submitted, might this cause an issue?

@ped59430
Copy link

The freqDist attribute is not reactive if not declared in data.

You can use this.$set(qData, 'freqDist', yourAjaxReceivedValues) to make it reactive.

See this docs

@David-Desmaisons
Copy link
Owner

@nboughton any news on this?

@nboughton
Copy link
Author

I've tried adding freqDist as part of the template data:

data() {
    return {
    ...
      qData: {
        timeSeries: {},
        freqDist: {}
      },
      layout: {
        freq: {
          title: "Draw Frequency",
          barmode: "stack"
        }
      },
...
}

And using set to ensure the data is reactive:

onSubmit() {
      this.$axios
        .post("/query", this.params)
        .then(res => {
          this.$set(this.qData, "freqDist", res.data.freqDist);
          this.$set(this.qData, "timeSeries", res.data.timeSeries);
          this.$set(this.qData, "mainTable", res.data.mainTable);
        })
        .catch(err => alert(err));
    },

However the chart still does not display as stacked bar data.

@David-Desmaisons
Copy link
Owner

Could you create a jsfiddle?

@nboughton
Copy link
Author

I'm attempting to but I'm not sure how to load vue-plotly on there. I've never used jsfiddle before and the server backend that I send ajax requests to is not deployed publicly. I usually just bake it into a docker image for testing and running.

@ped59430
Copy link

You can use unpkg https://unpkg.com/ to upload your npm packages in jsfiddle.

For the backend, maybe you can just copy and hardcode a subset of the data, and trigger the onSubmit() from a button?

@nboughton
Copy link
Author

https://jsfiddle.net/hybacw74/1/

I still can't get it to run vue-plotly

@jomarahi
Copy link

Try this:
<plotly ref="plot" :data="qData.freqDist" :layout="layout.freq" />

and add a watch on your layout.freq and qData.freqDist:

watch: {
    'qData.freqDist': {
      async handler (val) {
        await this.$nextTick()
        this.$refs.plot.schedule({ replot: false })
      },
      deep: true
    },
    'layout.freq': {
      async handler (val) {
        this.$refs.plot.innerLayout = val
        await this.$nextTick()
        this.$refs.plot.schedule({ replot: false })
      },
      deep: true
    }
  }

@nboughton
Copy link
Author

This works perfectly.

Thank you very much!

@ped59430
Copy link

ped59430 commented Jun 25, 2020

Worked also on my bar plot ! Thanks !!

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

4 participants