score:1
Looking at your code if you're trying this.data.push
its understandable that its telling you its undefined.
To get to your data prop in your fetchData method youd have to use
this.chartOptions.series[0].data.push
I'm not sure where you're firing fetchData either in that code. Try move it to your created/mounted methods in the vue lifecycle, you can then change your chartOptions to a computed or watcher, setting data in the data() method and calling it in your chartOptions with this.data.
UPDATE:
On click is fine for your get request if it's firing keep that the same, its where you're then setting it thats the issue.
I refactored your request, if its successful when you test it response.data should give you the results you need, not sure why you need to parse it unless its returning a json blob as a string?
I also added a v-if
to your chart renderer, if this.data
is empty then don't render. See how you get on with that.
import { Chart } from "highcharts-vue";
import Highcharts from "highcharts";
import exportingInit from "highcharts/modules/exporting";
//import stockInit from "highcharts/modules/stock";
//stockInit(Highcharts);
exportingInit(Highcharts);
export default {
props: {
partsdata: {
type: Array
}
},
methods: {
fetchData() {
this.$http.get('http://127.0.0.1:5000/data/')
.then(response => {
this.data.push(JSON.parse(response.data))
})
}
},
watch: {
data: function() {
this.chartOptions.series[0].data.push(this.data)
}
},
components: {
highcharts: Chart
},
data() {
return {
data: [],
chartOptions: {
series: [{
data: [] // sample data
}]
}
}
}
};
</script>
<template>
<div>
<button @click="fetchData" class="btn-primary">Get Data</button>
<highcharts if="data.length > 0" :options="chartOptions" ></highcharts>
</div>
</template>
score:0
You need to correctly get data and change chartOptions:
<template>
<div>
<highcharts class="hc" :options="chartOptions" ref="chart"></highcharts>
<button @click="fetchData" class="btn-primary">Get Data</button>
</div>
</template>
<script>
export default {
methods: {
fetchData() {
fetch('https://api.myjson.com/bins/ztyb0')
.then(response => {
return response.json()
})
.then(data => {
this.chartOptions.series[0].data = data;
})
}
},
data() {
return {
chartOptions: {
series: [{
data: []
}]
}
};
}
};
</script>
Live demo: https://codesandbox.io/s/highcharts-vue-demo-05mpo
Source: stackoverflow.com
Related Query
- VueJS App put data from GET request inside an array
- change VueJS component data value from inside Highchart event
- Highcarts won't redraw after fetching data from axios request in VueJS
- Highcharts, how to get data from array on same js page instead of external JSON
- (jQuery Highchart) Is there any way to put extra custom data inside Tooltip Box?
- How get data name in Highcharts pie chart legend instead of "Slice" using array of values?
- get json data from my controller in highcharts.js
- How to populate a Highcharts axis with string formatted data from a PHP array
- Highcharts get data from database
- Passing data to highcharts from javascript array or variable
- How To Get Data From Database To Highcharts Plugin in cakephp
- Highcharts categories from data array
- R highcharter get data from plots saved as html
- How to get the last 10 objects only from JSON data
- Can we get index from series data in highcharts
- vb.net getting data from datatable using array
- When using Highcharts, how do you get the point name from a data point series?
- Highcharts data from a variable is not working but from works fine from an array
- Function to draw a polygon from a scatterplot with nested array data
- Laravel get two value array count from controller in javascript
- Pass array from js for loop to highcharts series data
- Include additional highcharts source data in angular2 app
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Can I add on the webpage, data that I get from a Highcharts function?
- VB.net 2 dimensional array with data from a list
- How do I get data from a RESTful API JSON response in React?
- How to get region/province code from IP address
- How filter json data with date from datepicker Angular2 app
- How to get data for series and categories in highcharts-convert.js from mysql
- How to get data from multiple tables of MySQL DB and manuplate it using PHP to display graphs?
More Query from same tag
- LINQ that groups data and returns series for chart
- HighCharts Do not display
- How to add a background image (pattern) to highchart column graph?
- Add line to 3d column chart in Highcharts
- Data label not showing in some pie chart handles Highchart
- Highcharts stacking bar chart border not displaying on right side
- Highcharts: Duplicate X-Axis Labels when dataGrouping is enabled (by Month)
- Highcharts Column Zones
- Plotting line in Linechart with values taken from the textarea
- Magento: TypeError: N is not a function
- Highcharts - Line disappears when using logarithmic axis
- Highcharts | Line height control for plot band labels in styled mode
- Highcharts graph does not update with firebase
- How to set minutes as units in Highstock chart using data from CSV
- Border around legend item in highcharts
- How to add texts to a graph in Highcharts
- Highcharts - Data won't get loaded into chart on Android WebView
- HighCharts X-Axis Date Not Working (00:00)
- Highcharts crosshair label is behind legend
- Strange tooltip behavior with long series in highcharts
- Show labels per serie in Highstock.js as in Highcharts.js
- Highcharts-limit display of categories
- Max number of flags on highstock control
- why is my ionic not responding with the waterfall diagram highchart
- Attach arbitrary data to Highcharts data points
- highchart not displaying in the center on mobile screen
- HighCharts: how to update bar color when updating the point value
- Organization Chart Double Color in 1 Box
- lineWidth on both sides of chart
- Create multiple Pie Highcharts for multiple series