Bar chart from Vue-chartjs doesn't render - vue.js

In my Vue project I cannot render the Bar Chart I've created using vue-chartjs
I've tried reinstalling vue-chartjs and update my component, but nothing work.
I wonder if it's the problem with the component itself or I do rendering in a wrong way?
BarChart component
<script>
import { Bar } from "vue-chartjs";
export default {
extends: Bar,
mounted() {
this.renderChart(
{
labels: [
"London",
"New York",
"New Zeland",
],
datasets: [
{
label: "Data One",
backgroundColor: "#f87979",
data: [
83,
26,
4,
]
}
]
},
{ responsive: true, maintainAspectRatio: false, height: 200 }
);
}
};
</script>
Home component:
<template>
<v-container class="grey lighten-5">
<v-col cols="12" sm="8">
<v-card class="pa-2" outlined align="center">
<BarChart/>
<div>CHART</div>
</v-card>
</v-col>
</v-container>
</template>
<script>
import BarChart from "#/components/charts/BarChart";
export default {
components: {
BarChart
},
};
</script>
<style></style>

The mistake in the method this.renderChart(). I had to look at the documentation to figure out how it should be structured.
The method this.renderChart() is provided by the Bar component and accepts two parameters: both are objects. The first one is your chart data, and the second one is an options object.
More in docs - https://www.chartjs.org/docs/latest/charts/bar.html
This worked for me:
<script>
import { Bar } from "vue-chartjs";
export default {
extends: Bar,
mounted() {
this.renderChart(
{
labels: [
"London",
"New York",
"New Zeland",
],
datasets: [
{
label: "Data One",
backgroundColor: "#f87979",
data: [
83,
26,
4,
]
}
]
},
{ responsive: true }
);
}
};
</script>

Related

How to dynamically insert text in Ckeditor5 for Vue 2

My application provides many selectable standard paragraphs which users can insert at any point. In a previous version insertion was simple: CKEDITOR.instances[editorId].insertHTML(text).
I'm trying to use v5 api with model.insertContent(text) but get error:
"vue.runtime.esm.js:3020 TypeError: t2.is is not a function
at bl.rp (converters.js:771:21)
at bl.fire (emittermixin.js:199:30)
at <computed> (observablemixin.js:262:16)
at VueComponent.testInsert (Test.vue:29:1)"
Here's the composition file. I have tried accessing the insertContent method from this.editor and from the apiReference returned from the #ready event;
<template>
<div>
<button #click="testInsert('abracadabra')">Insert literal content</button>
<ckeditor tag-name="textarea" :editor="editor" v-model="doc.HTML" #ready="editorReady" :config="editorConfig"></ckeditor>
</div>
</template>
<script>
import ClassicEditor from '#ckeditor/ckeditor5-build-classic';
export default {
name: 'testEditorInsert',
mounted() {
},
data() {
return {
doc: {ID: 0, HTML: "This is a sample text. Insert here? This is the remainder of the sample text"},
editor: ClassicEditor,
editorData: 'loading',
editorConfig: {
toolbar: [ 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
},
editorApi:null ,
}
},
methods: {
testInsert: function(text) {
console.log(this.editorApi, text);
//this.editor.model.insertContent(text);
this.editorApi.model.insertContent(text);
},
editorReady: function(editor) {
this.editorApi = editor;
}
},
}
</script>

Vuemapbox markers are showing at the bottom of the page

I am trying to build a map application with the vuemapbox library , but the strange thing is , all the markers are showing at the bottom of the page which is strange , can any one help me with it ?
<template>
<div class="home">
<MglMap :accessToken="accessToken" :mapStyle="mapStyle" #load="onMapLoaded">
<MglMarker
:coordinates.sync="locations"
color="blue"
v-for="(location, index) in pins"
:key="index"
/>
</MglMap>
</div>
</template>
<script>
// # is an alias to /src
import Mapbox from "mapbox-gl";
import {
MglMap,
MglMarker
} from "vue-mapbox";
export default {
name: "Home",
components: { MglMap, MglMarker },
data() {
return {
accessToken:"xxx",
mapStyle: "mapbox://styles/mapbox/streets-v11",
pins: [
[20.341979525348204, 85.8345150468384],
[25.581627613058714, 80.87795332144299],
[25.199370930176993, 95.86881932189225],
],
};
},
beforeMount() {
this.$store.dispatch("set_user_location");
},
computed: {
locations() {
return this.$store.getters.getThisUserMarker;
},
},
created() {
this.mapbox = Mapbox;
},
methods: {
async onMapLoaded(event) {
// in component
this.map = event.map;
const asyncActions = event.component.actions;
await asyncActions.flyTo({
center: this.locations,
zoom: 4,
speed: 1,
});
},
},
};
</script>
This is what i have done so far , but having this strange issue , please help , Every help is appreciated .
Make shure that you have loaded mabpox css.
Try to set height for MglMap
<MglMap
width="100%"
height="100%"
...
/>

Draggable in Vue 3 won't display value

I am using Vue draggable to sort items from my Store.js by drag and drop (I've simplified my example here using only ['a', 'b', 'c'] as my store data).
I am also using a computed property made accessible from the setup()
<draggable v-model="myList" item-key="id" #start="drag=true" #end="drag=false" >
<template #item="{card}">
<p>{{ card }}</p>
</template>
</draggable>
import draggable from 'vuedraggable';
export default {
name: "Dashboard",
components: {
draggable
},
setup() {
const cards = computed(() => {
return ['a', 'b', 'c']
})
return {
cards
}
}
}
I know the template iterates through cards but no value is displayed or is neither accessible.
In Vue 3 - When setup is executed, the component instance has not been created yet. As a result, you will not have access to data, computed, methods component options.
Reference:
https://v3.vuejs.org/guide/composition-api-setup.html#accessing-component-properties
Also in Draggable component, the array item will be accessed by element variable.
Updated template code:
<draggable v-model="myList" item-key="id" #start="drag=true" #end="drag=false" >
<template #item="{element}">
<p>{{ element.value }}</p>
</template>
</draggable>
Try changing the component code as follows,
import draggable from 'vuedraggable';
export default {
name: "Dashboard",
components: {
draggable
},
data:function(){
return {
drag:false
}
},
computed:{
myList:function(){
return [{id:1,value:'Card A'},{id:2, value:'Card B'}];
}
}
}
yarn add vue-draggable-next
<draggable class="w-full mt-5 dragArea list-group" :list="list" #change="log">
<div
class="max-w-md p-2 mb-5 border cursor-pointer list-styles"
v-for="element in list"
:key="element.name"
>
{{ element.name }}
</div>
</draggable>
</template>
<script>
import { defineComponent } from "vue";
import { VueDraggableNext } from "vue-draggable-next";
export default defineComponent({
components: {
draggable: VueDraggableNext,
},
data() {
return {
enabled: true,
list: [
{ name: "Medical science", id: 1 },
{ name: "Allied Medicine", id: 2 },
{ name: "Defense Service", id: 3 },
{ name: "Education training", id: 4 },
{ name: "Economics & Commerce", id: 5 },
{ name: "Banking & Finance", id: 6 },
{ name: "Enginnering", id: 7 },
{ name: "science", id: 8 },
],
dragging: false,
};
},
methods: {
log(event) {
console.log(event);
},
},
});
</script>

Cannot render multiple times the same amchart3 graph in a vue component

I'm using amcharts3 to generate graphs, Bootstrap 4 for the style and Vue2 for the components. I have a parent component which shows a donut chart which is a component on its own, and I want to render those charts many times as I need
Parent component
<template>
<div class="w-100 container-fluid">
<div class="row">
<!-- Here it goes the Donut Charts -->
</div>
</div>
</template>
<script>
import donutChart from './donutChart';
export default {
components:{
'donut-chart': donutChart
},
data(){
return{
graficos: [
{id: 'grafico', valor:100, valor2: 0},
{id: 'dona', valor:75, valor2: 25},
{id: 'homero', valor:50, valor2:50},
]
}
}
}
</script>
<style></style>
donutChart.vue (the amcharts3 library is already loaded in the Vue project)
<template>
<div class="col">
<div :id="this.dato.id"></div>
</div>
</template>
<script>
export default {
props:{
dato: {
type: Object,
default: {id: 'chartdiv', valor:50, valor2:50}
}
},
data() {
return {
}
},
created: function(){
console.log(this.dato)
AmCharts.makeChart( this.dato.id, {
"type": "pie",
"theme": "none",
"responsive": {
"enabled": true
},
"minWidth": 200,
"maxWidth": 400,
"dataProvider": [ {
"title": "et0",
"value": this.dato.valor
},
{
"title": "Restante",
"value": this.dato.valor2
} ],
"startDuration": 0,
"titleField": "title",
"valueField": "value",
"labelRadius": 5,
"radius": "40%",
"innerRadius": "80%",
"allLabels": [{
"y": "46%",
"align": "center",
"size": 14,
"text": "50%",
"color": "#555"
}]
});
},
mounted: function(){
},
methods:{
}
}
</script>
<style></style>
The problem is the donutChart.vue component is rendered in the parent, and it shows the chart
<donut-chart></donut-chart>
But when I try to render multiple times the same component and/or passing data via props the chart doesn't render at all
<donut-chart :dato="{id: 'grafico', valor: 100, valor2: 0}"></donut-chart>
<donut-chart :dato="{id: 'dona', valor: 75, valor2: 25}"></donut-chart>
<donut-chart :dato="{id: 'homero', valor: 50, valor2 :50}"></donut-chart>
I'm doing something wrong?
Well. I've managed to see what's going on and it looks so stupid. In donutChart.vue thereĀ“s an style that only applies to #chartdiv element, I didn't post in the question because I didn't figure that code until now. Now I'm applying the same style for every component and now the charts are renderized

Sort Vue data table by selection

Is there a way to sort a v-data-table by the selection column?
I would like to multisort my v-data-table. First by selection, so the selected ones are always on top and second by name. So far I got this:
<template>
<v-app>
<div id="app">
<v-data-table
:headers="tableHeaders"
:items="selectables"
:show-select="true"
:sort-by="['isSelected', 'name']"
multi-sort
v-model="output"
return-object
>
</v-data-table>
</div>
</v-app>
</template>
<script>
export default {
data() {
return {
output: {},
tableHeaders: [
{
text: "name",
value: "name",
},
],
selectables: [
{
name: "toni",
},
{
name: "hans",
},
{
name: "fritz",
},
],
};
},
};
</script>