Skip to content

Commit

Permalink
Chart.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sv2 committed Apr 24, 2020
1 parent 933c2f1 commit 769920d
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/menu/menudrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export default {
this.$emit('input', val);
},
mini: function(val) {
this.setMini(val);
if (!this.autoExpand) {
this.setMini(val);
}
},
miniState: function(val) {
this.$emit('update:mini', val);
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<q-btn dense flat round icon="menu" @click="leftShown = !leftShown" />

<q-toolbar-title>
dashblocks
dashblocks.io
</q-toolbar-title>

<q-space></q-space>
Expand Down Expand Up @@ -102,7 +102,7 @@ export default {
{ id: '1', title: 'Dashboard', link: '/', icon: 'dashboard' },
{ id: '3', title: 'Forms', link: '/forms', icon: 'mdi-playlist-edit' },
{ id: '4', title: 'Tables', link: '/tables', icon: 'mdi-table' },
{ id: '5', title: 'Charts', link: '/charts', icon: 'pie_chart' },
{ id: '5', title: 'Charts', icon: 'pie_chart', items: [{ id: 'chartjs', title: 'Chart.js', link: '/chartjs', icon: 'mdi-chart-bar' }] },
{
id: '6',
title: 'Style',
Expand Down
6 changes: 6 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import About from './views/About.vue';
import DashblocksShowcase from './views/DashblocksShowcase.vue';
import Typography from './views/typography.vue';
import MaterialIcons from './views/materialicons.vue';
import ChartJsShowcase from './views/ChartJsShowcase.vue';
import Mdi from './views/mdi.vue';

Vue.use(Router);
Expand All @@ -21,6 +22,11 @@ export default new Router({
name: 'showcase',
component: DashblocksShowcase
},
{
path: '/chartjs',
name: 'chartjs',
component: ChartJsShowcase
},
{
path: '/typography',
name: 'typography',
Expand Down
5 changes: 3 additions & 2 deletions src/styles/quasar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ a:hover {
background: linear-gradient(to right, #2c5364, #203a43, #0f2027); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}


.ub-page {
@media (max-width: $breakpoint-xs-max) {
padding: 4px 8px 8px 8px;
}
@media (min-width: $breakpoint-sm-min) and (max-width: $breakpoint-md-max) {
padding: 4px 16px 16px 16px;
padding: 4px 12px 16px 12px;
}
@media (min-width: $breakpoint-lg-min) {
padding: 4px 24px 24px 24px;
padding: 4px 12px 24px 12px;
}
}

283 changes: 283 additions & 0 deletions src/views/ChartJsShowcase.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
<template>
<q-page class="ub-page">
<div class="row items-center">
<div class="col-md-12 q-ma-sm">
<div class="text-h3">Chart.js Showcase</div>
</div>
</div>
<db-dashboard :dbspec="dbspec" :dbdata="dbdata" :dark="isDark"> </db-dashboard>
<div class="row items-center">
<div class="col-md-12 q-ma-sm"></div>
</div>
</q-page>
</template>

<script>
import { DbData, DbColors } from 'dashblocks';
import { demodashboard } from '../mixins/demodashboard';
export default {
name: 'ChartJsShowcase',
components: {},
mixins: [demodashboard],
data() {
return {
refreshIntervalId: null,
dbdata: new DbData(),
dbspec: {
layout: {
type: 'grid'
},
widgets: [
{
id: 'wTrend',
type: 'DbChartjsLine',
cspan: 16,
height: 250,
properties: {
options: {
elements: { point: { radius: 0 } },
animation: { duration: 0 },
responsive: true,
scales: {
xAxes: [{ type: 'time', display: true, time: { unit: 'second' } }],
yAxes: [{ display: true, ticks: { beginAtZero: true, min: 0, max: 1000 } }]
}
}
}
},
{
id: 'w1',
type: 'DbChartjsLine',
cspan: 4,
height: 250,
properties: {
options: {
maintainAspectRatio: false
}
}
},
{
id: 'w2',
type: 'DbChartjsBar',
cspan: 4,
height: 250
},
{
id: 'w3',
type: 'DbChartjsHorizontalBar',
cspan: 4
},
{
id: 'w4',
type: 'DbChartjsPie',
cspan: 4
},
{
id: 'w5',
type: 'DbChartjsDoughnut',
cspan: 4,
height: 250
},
{
id: 'w6',
type: 'DbChartjsPolarArea',
cspan: 4,
height: 250
},
{
id: 'w7',
type: 'DbChartjsRadar',
cspan: 4,
height: 250
},
{
id: 'w8',
type: 'DbChartjsBar',
cspan: 4,
height: 250
},
{
id: 'w9',
type: 'DbChartjsBubble',
cspan: 8,
height: 300
},
{
id: 'w10',
type: 'DbChartjsScatter',
cspan: 8,
height: 300,
properties: {
options: {
scales: {
xAxes: [
{
type: 'linear',
position: 'bottom'
}
]
}
}
}
}
]
}
};
},
created() {
this.initialize();
},
beforeDestroy: function() {
if (this.refreshIntervalId) {
clearInterval(this.refreshIntervalId);
}
},
methods: {
initialize: function() {
let dataTrend = {
datasets: [
{
label: 'Number of Requests',
data: []
}
]
};
let dts = Date.now() - 100 * 1000;
for (let i = 0; i < 100; i++) {
dataTrend.datasets[0].data.push({
t: new Date(dts),
y: this.getRandomInt(100, 1000)
});
dts += 1000;
}
let dataOneSeries = {
labels: ['January', 'February', 'March', 'April'],
datasets: [
{
label: 'Data One',
data: [10, 20, 30, 100]
}
]
};
let dataTwoSeries = {
labels: ['January', 'February', 'March', 'April'],
datasets: [
{
label: 'Data One',
data: [10, 20, 30, 100]
},
{
label: 'Data Two',
data: [50, 10, 70, 11]
}
]
};
let dataBubbleTwoSeries = {
labels: ['January', 'February', 'March', 'April'],
datasets: [
{
label: 'Data One',
data: [
{ x: 10, y: 20, r: 10 },
{ x: 20, y: 20, r: 20 },
{ x: 30, y: 30, r: 30 },
{ x: 100, y: 200, r: 100 }
]
},
{
label: 'Data Two',
data: [
{ x: 30, y: 50, r: 50 },
{ x: 60, y: 60, r: 60 },
{ x: 80, y: 70, r: 70 },
{ x: 100, y: 200, r: 10 }
]
}
]
};
let dataScatterTwoSeries = {
labels: ['January', 'February', 'March', 'April'],
datasets: [
{
label: 'Data One',
data: [
{ x: 10, y: 20 },
{ x: 20, y: 20 },
{ x: 30, y: 30 },
{ x: 100, y: 200 }
]
},
{
label: 'Data Two',
data: [
{ x: 30, y: 50 },
{ x: 60, y: 60 },
{ x: 80, y: 70 },
{ x: 100, y: 200 }
]
}
]
};
let d1 = JSON.parse(JSON.stringify(dataTwoSeries));
let d2 = JSON.parse(JSON.stringify(dataOneSeries));
let d3 = JSON.parse(JSON.stringify(dataTwoSeries));
let d4 = JSON.parse(JSON.stringify(dataOneSeries));
let d5 = JSON.parse(JSON.stringify(dataTwoSeries));
let d6 = JSON.parse(JSON.stringify(dataOneSeries));
let d7 = JSON.parse(JSON.stringify(dataTwoSeries));
let d8 = JSON.parse(JSON.stringify(dataTwoSeries));
let d9 = JSON.parse(JSON.stringify(dataBubbleTwoSeries));
let d10 = JSON.parse(JSON.stringify(dataScatterTwoSeries));
this.dbdata.setWData('w1', { data: d1 });
this.dbdata.setWData('w2', { data: d2 });
this.dbdata.setWData('w3', { data: d3 });
this.dbdata.setWData('w4', { data: d4 });
this.dbdata.setWData('w5', { data: d5 });
this.dbdata.setWData('w6', { data: d6 });
this.dbdata.setWData('w7', { data: d7 });
this.dbdata.setWData('w8', { data: d8 });
this.dbdata.setWData('w9', { data: d9 });
this.dbdata.setWData('w10', { data: d10 });
this.dbdata.setWData('wTrend', { data: dataTrend });
//let bw = 1;
// Dynamic updates
this.refreshIntervalId = setInterval(() => {
this.performRefresh();
}, 1000);
},
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
},
performRefresh() {
console.log('Refreshing charts ... ');
let v = this.dbdata['w2'].data.datasets[0].data[0];
this.dbdata['w2'].data.datasets[0].data[0] = v + 10;
// We can add dynamically any prop to dataset entry ...
//comp.dbdata['w2'].data.datasets[0].borderWidth = bw++;
this.dbdata.touch('w2');
// Update (shift) trend timeline
this.dbdata['wTrend'].data.datasets[0].data.shift();
this.dbdata['wTrend'].data.datasets[0].data.push({
t: new Date(),
y: this.getRandomInt(100, 1000)
});
this.dbdata.touch('wTrend');
}
}
};
</script>

0 comments on commit 769920d

Please sign in to comment.