statnett / vue-plotly

A vue wrapper for plotly.js chart library
MIT License
119 stars 28 forks source link

JSON input to vue to be plotted with plotly #17

Closed AhmedSHelmi closed 5 years ago

AhmedSHelmi commented 5 years ago

Hey there, I am new to Vue. I am enjoying it so far. However I am stuck in a problem I need help with. straight to the topic, I don’t know to to pass the result of an Ajax using Axios call to a variable to render it to my scatter plot using your library . Here is how I tried to do it.

 data () {
       return {
        //flag is defined as an array that I push the ajax response to
       flag:[],
       scatter:{
         data: [{ x: [2, 300,36], y: [200, 400,800] }],
         layout: {'title': String(this.flag)},
         options: {}
       },
  },        

mounted(){
axios.get('http://192.168.1.10:8000/books/api/?format=json')
.then(response => (this.flag = response)) } when I try to use flag in layout it says undefined. This is so strange how flag could it be undefined and why? I would appreciate your help. thanks in advance.