-
-
Notifications
You must be signed in to change notification settings - Fork 838
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
Pass Reactive data into Scatterplot #69
Comments
Ah, the problem is that I am passing in an array of objects through a reactiveProp. Is there a work around? The problem is that I have around 2000 objects with different x and y values being called in from an API. |
Not right now. The mixin is not the best fit for all use cases, because it depends on how you populate your data. |
Hey @sdzharkov well I tried a few things out, however I could not get it working. The watcher does not see any changes of It accepts the following data However I could not reproduce the error you got. 🤔 The mixins are kind of hacky, because Chart.js does not support live data nor automatic chart updating on new data. What you could do, is like said before to trigger the update by yourself. You can access the chart instance at There are many ways how to do it. You could use like said before an event bus or something. |
Thanks @apertureless that was super helpful.
<div class="lineChart">
<line-chart :chart-data="obj" :test="datasetsfull"></line-chart>
</div>
computed: {
datasetsfull () {
return {
label: 'graph',
type: 'line',
datasets: [
{
label: '/data',
backgroundColor: '#E1F5CA',
data: this.GetLineGraphData1 // a getter from Vuex
},
{
label: '/analytics',
backgroundColor: '#67C6AE',
data: this.GetLineGraphData2
}
]
}
}
beforeCreate () {
this.$store.dispatch('FETCH_LINE_GRAPH')
},
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default Line.extend({
mixins: [reactiveProp],
props: ['test', 'options'],
data () {
return {
obj: {
label: 'graph',
type: 'line',
datasets: [
{
label: '/data',
backgroundColor: '#E1F5CA',
data: [ //This is just initial data I pass to make sure it renders as a Scatterplot
{
x: 5,
y: 6
},
{
x: 7,
y: 8
}
]
}
]
}
}
},
mounted () {
if (this.chartData) {
this.renderChart(this.obj, {responsive: true, maintainAspectRatio: false})
}
},
watch: {
test: function () {
this.renderChart(this.test, { //Right here is where the new data will be rendered
responsive: true,
maintainAspectRatio: true,
scales: {
yAxes: [{
ticks: {
min: 90000000,
max: 170000000
}
}],
xAxes: [{
position: 'bottom',
ticks: {
min: 1,
max: 100000000
}
}]
}
})
}
}
}) |
Cool, thanks for the example and workaround! May help some people! |
Is it possible to create a line chart that uses my own predefined x & y axis data? Currently, the line chart accepts an array of values that correspond to the array of labels. However, Chart.js allows data to be declared like this:
data: {
datasets: [{
label: 'Scatter Dataset',
data: [{x: -10,y: 0}, {x: 0,y: 10}]
}]
Anyways, is it possible to do this with Vue-chartjs? I have been attempting it but get a "me.ticks.map is not a function" typeError.
The text was updated successfully, but these errors were encountered: