0

I need to display apex chart (Brush Chart). I am trying to append data from API into Array. i have given code below and also API data.

I used console to check that the data is coming correctly from API but not appending to series array

<div id="app" style="background:white">
  <div id="chart1">
    <apexchart type=line height=230 :options="chartOptionsArea" :series="series" />
  </div>
  <div id="chart2">
    <apexchart type=area height=130 :options="chartOptionsBrush" :series="series" />
  </div>
</div>

below is my VUEjs code

data() {
  return {
    series: [{
      data: this.generateDayWiseTimeSeries(new Date('01 Jan 
        2014 ').getTime(),185, {
        min: 30,
        max: 90
      })
    }],
    chartOptionsArea: {
      chart: {
        id: 'chartArea',
        toolbar: {
          autoSelected: 'pan',
          show: false
        }
      },
      colors: ['#546E7A'],
      stroke: {
        width: 3
      },
      dataLabels: {
        enabled: false
      },
      fill: {
        opacity: 1,
      },
      markers: {
        size: 0
      },
      xaxis: {
        type: 'datetime'
      }
    },
    chartOptionsBrush: {
      chart: {
        id: 'chartBrush',
        brush: {
          target: 'chartArea',
          enabled: true
        },
        selection: {
          enabled: true,
          xaxis: {
            min: new Date('01 Jan 2014').getTime(),
            max: new Date('09 Jan 2014').getTime()
          }
        },
      },
      colors: ['#008FFB'],
      fill: {
        type: 'gradient',
        gradient: {
          opacityFrom: 0.91,
          opacityTo: 0.1,
        }
      },
      xaxis: {
        type: 'datetime',
        tooltip: {
          enabled: false
        }
      },
      yaxis: {
        tickAmount: 2
      }
    }
  }
}

below is Function

generateDayWiseTimeSeries: function() {
  var i = 0;
  var self = this;
  var series;

  axios
    .get("http://172.31.0.114:5000/api/eco/BNG-JAY-136-001")
    .then(function(res) {
      self.series = res.data; //not working 
    })

  return series;
}

API data

[
  [
    "2019-5-23",
    0
  ],
  [
    "2019-5-24",
    0
  ],
  [
    "2019-5-25",
    0
  ],
  [
    "2019-5-26",
    0
  ],
  [
    "2019-5-27",
    0
  ],
  [
    "2019-5-28",
    0
  ],
  [
    "2019-5-29",
    0
  ],
  [
    "2019-5-30",
    0
  ],
  [
    "2019-5-31",
    0
  ]
]
1

2 Answers 2

0

You can use updateSeries method or you can directly update the value of series. Please check below code

Code Snippet

generateDayWiseTimeSeries: function() {
    var me = this;
    axios.get("data.json")
        .then(function(res) {
            me.series[0].data = res.data;
            //OR you can use updateSeries method

            /* me.$children[0].updateSeries([{
               data: res.data
             }]);*/
        });

    return [];
}

You can check here with working fiddle.

Sign up to request clarification or add additional context in comments.

1 Comment

glad to help you :) @pavan
0

generateDayWiseTimeSeries function return undefined variable => series.

Assign returned data to series instead of self.series.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.