Vue UI Components Documentation
Vue Chart Component
The Chart component for Vue represents a lightweight and powerful chart widget. It offers many advanced features and supports three different rendering technologies - SVG, HTML5 Canvas & VML.
Prerequisites
Refer to Vue Getting Started before you start with this help topic.
Configuration
After you have created your App.vue file, here is how you should structure it:
The Chart component for Vue requires the following import:
import JqxChart from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxchart.vue';
Add the jqxChart component to the components section of the the Vue class:
components: { JqxChart },
Template
The App.vue has a <template>
structural tag where we determine the application structure.
There we will also set the tags for the new components - <JqxChart/>
<template> <JqxChart style="width: 850px; height: 500px" :title="'Fitness & exercise weekly scorecard'" :description="'Time spent in vigorous exercise'" :showToolTip="false" :enableAnimations="true" :padding="padding" :titlePadding="titlePadding" :source="sampleData" :xAxis="xAxis" :seriesGroups="seriesGroups" :colorScheme="'scheme04'"> </JqxChart></template>
Properties
The properties of the <JqxChart/> component are defined in the data
member of the Vue class.
We should put them in the return object of the data function:
data: function () { return { sampleData: [ { Day: 'Monday', Keith: 30, Erica: 15, George: 25 }, { Day: 'Tuesday', Keith: 25, Erica: 25, George: 30 }, { Day: 'Wednesday', Keith: 30, Erica: 20, George: 25 }, { Day: 'Thursday', Keith: 35, Erica: 25, George: 45 }, { Day: 'Friday', Keith: 20, Erica: 20, George: 25 }, { Day: 'Saturday', Keith: 30, Erica: 20, George: 30 }, { Day: 'Sunday', Keith: 60, Erica: 45, George: 90 } ], padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, xAxis: { dataField: 'Day', type: 'basic' }, seriesGroups: [ { type: 'column', valueAxis: { minValue: 0, maxValue: 100, unitInterval: 10, title: { text: 'Time in minutes' } }, series: [ { dataField: 'Keith', displayText: 'Keith' }, { dataField: 'Erica', displayText: 'Erica' }, { dataField: 'George', displayText: 'George' } ] } ] }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxChart style="width: 850px; height: 500px" @click="onChartClick()" :title="'U.S. Stock Market Index Performance'" :description="'NASDAQ Composite compared to S&P 500'" :showLegend="true" :enableAnimations="true" :padding="padding" :titlePadding="titlePadding" :source="dataAdapter" :xAxis="xAxis" :valueAxis="valueAxis" :seriesGroups="seriesGroups" :colorScheme="'scheme04'"></JqxChart>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { onChartClick: function () { // Do something... }}
Methods
To use a component's method we should have its reference. In Vue we refer to a component by the special $refs
property.
Before that we need to add the desired name reference to that component:
<JqxChart ref="chart"></JqxChart>
Here how you can use a component's method:
this.$refs.chart.refresh();
methods: { // Add here all used callbacks and/or events onChartClick: function () { // Do something when clicking on the chart this.$refs.chart.refresh(); }}
If we want to add additional methods we should also implement them in the methods
member.
In case we need to do some precalculation or something else before the components are rendered, we should use the beforeCreate
member.
It depends on the case.
If you have followed the above steps, you App.vue file would look like this:
App.vue:
<template> <JqxChart style="width: 850px; height: 500px" ref="chart" @click="onChartClick()" :title="'Fitness & exercise weekly scorecard'" :description="'Time spent in vigorous exercise'" :showToolTip="false" :enableAnimations="true" :padding="padding" :titlePadding="titlePadding" :source="sampleData" :xAxis="xAxis" :seriesGroups="seriesGroups" :colorScheme="'scheme04'"> </JqxChart></template> <script> // Import the components that will be used import JqxChart from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxchart.vue'; export default { components: { // Adding imported widgets here JqxChart }, data: function () { // Define properties which will use in the widget return { sampleData: [ { Day: 'Monday', Keith: 30, Erica: 15, George: 25 }, { Day: 'Tuesday', Keith: 25, Erica: 25, George: 30 }, { Day: 'Wednesday', Keith: 30, Erica: 20, George: 25 }, { Day: 'Thursday', Keith: 35, Erica: 25, George: 45 }, { Day: 'Friday', Keith: 20, Erica: 20, George: 25 }, { Day: 'Saturday', Keith: 30, Erica: 20, George: 30 }, { Day: 'Sunday', Keith: 60, Erica: 45, George: 90 } ], padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, xAxis: { dataField: 'Day', type: 'basic' }, seriesGroups: [ { type: 'column', valueAxis: { minValue: 0, maxValue: 100, unitInterval: 10, title: { text: 'Time in minutes' } }, series: [ { dataField: 'Keith', displayText: 'Keith' }, { dataField: 'Erica', displayText: 'Erica' }, { dataField: 'George', displayText: 'George' } ] } ] } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events onChartClick: function () { // Do something when clicking on the chart this.$refs.chart.refresh(); } } }</script> <style></style>
Chart Example
<template> <JqxChart style="width: 850px; height: 500px" :title="'Economic comparison'" :description="'GDP and Debt in 2010'" :showLegend="true" :enableAnimations="true" :padding="padding" :titlePadding="titlePadding" :source="dataAdapter" :xAxis="xAxis" :columnSeriesOverlap="false" :seriesGroups="seriesGroups" :colorScheme="'scheme01'"> </JqxChart></template> <script> import JqxChart from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxchart.vue'; export default { components: { JqxChart }, data: function () { return { dataAdapter: new jqx.dataAdapter(this.source, { async: false, autoBind: true, loadError: (xhr, status, error) => { alert('Error loading "' + this.source.url + '" : ' + error); } }), padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, xAxis: { dataField: 'Country', gridLines: { visible: true }, valuesOnTicks: false }, seriesGroups: [ { type: 'column', valueAxis: { visible: true, unitInterval: 5000, title: { text: 'GDP & Debt per Capita($)<br>' } }, series: [ { dataField: 'GDP', displayText: 'GDP per Capita' }, { dataField: 'Debt', displayText: 'Debt per Capita' } ] }, { type: 'line', valueAxis: { visible: true, position: 'right', unitInterval: 10, title: { text: 'Debt (% of GDP)' }, gridLines: { visible: false }, labels: { horizontalAlignment: 'left' } }, series: [ { dataField: 'DebtPercent', displayText: 'Debt (% of GDP)' } ] } ] } }, beforeCreate: function () { this.source = { datatype: 'csv', datafields: [ { name: 'Country' }, { name: 'GDP' }, { name: 'DebtPercent' }, { name: 'Debt' } ], url: 'sampledata/gdp_dept_2010.txt' }; } }</script> <style></style>