Create doughnut chart component in Vuejs


Data Visualization is the important part of a commercial application. There are plenty of JavaScript library available for this task. In this series of post we are discussing about Chartjs and its Vue wrapper.

Creating Component may save your time and it increase the re-usability of the code.

Install dependencies

In-order to use Chartjs charts we need multiple dependency which can be installed using one of the following methods.


 yarn add vue-chartjs chart.js
 npm install vue-chartjs chart.js --save

Create component

In the component folder of the project add the following code and name the file Doughnut.js

import { Doughnut, mixins } from 'vue-chartjs'

export default {
  extends: Doughnut,  
  mixins: [mixins.reactiveProp],
  name: 'DoughnutChart',
  props: [{
    chartData: {
      type: Object,
      default: null
    },
    options: {
      type: Object,
      default: null
    }
  }],
  mounted() {
    this.renderChart(this.chartData, this.options)
  }
}

Using the component

In the page component we can import component and bind the data, and options.

<template>
  <div class="flex-container">
    <DoughnutChart :chartData="chartdata" :options="options" />
  </div>
</template>

<script>
// @ is an alias to /src
import DoughnutChart from '@/components/Doughnut'
export default {
  name: "Doughnut",
  components: { DoughnutChart 
  },
  data (){
    return {
    chartdata: {
      labels: ['January', 'February'],
      datasets: [
        {
          label: 'Data One',
          backgroundColor: '#f87979',
          data: [40, 20]
        },
         {
          label: 'Data Two',
          backgroundColor: '#5885af',
          data: [140, 120]
        }
      ]
    },
    options: {
      responsive: true,
      maintainAspectRatio: false
    },
    }

  }
  
};
</script>
<style>
.flex-container {
  display: flex;
}

</style>

A complete set of chart components will be available on Vue-chart-components Repository

Following vue-route post may interest you

Create line chart component in Vue


Data Visualization is the important part of a commercial application. There are plenty of JavaScript library available for this task. In this series of post we are discussing about Chartjs and its Vue wrapper.

Creating Component may save your time and it increase the re-usability of the code.

Create a Line Chart component

In-order to use Chartjs charts we need multiple dependency which can be installed using one of the following methods.

 yarn add vue-chartjs chart.js
 npm install vue-chartjs chart.js --save

Create component

In the component folder of the project add the following code and name the file LineChart.js

import { Line, mixins } from 'vue-chartjs'

export default {
  extends: Line,  
  mixins: [mixins.reactiveProp],
  name: 'LineChart',
  props: [{
    chartdata: {
      type: Object,
      default: null
    },
    options: {
      type: Object,
      default: null
    }
  }],
  mounted() {
    this.renderChart(this.chartData, this.options)
  }
}

We have used a mixin which combine the reactive props and Line chart from the vue-chartjs module.

Using the component

In the page component we can import component and bind the data, and options.

<template>
  <div class="flex-container">
    <LineChart :chartData="chartdata" :options="options" />
  </div>
</template>

<script>
// @ is an alias to /src
import  LineChart   from "@/components/LineChart"
export default {
  name: "LineChart",
  components: { LineChart
  },
  data (){
    return {
    chartdata: {
      labels: ['January', 'February'],
      datasets: [
        {
          label: 'Data One',
          backgroundColor: '#f87979',
          data: [40, 20]
        },
         {
          label: 'Data Two',
          backgroundColor: '#5885af',
          data: [140, 120]
        }
      ]
    },
    options: {
      responsive: true,
      maintainAspectRatio: false
    },
    }

  }
  
};
</script>
<style>

.flex-container {
  display: flex;
}
</style>

A complete set of chart components will be available on Vue-chart-components Repository

Following vue-route post may interest you

redirecting multiple routes in Vuejs


Sometimes we would like to have same route with different name, such guide to FAQ, help, how-to etc. What should we do when want to redirect same route against a bunch of routes ?. Here the alias came into picture

alias can be used in our index route file to redirect a route / a set of route to specific route. The following example will clarify this

import Vue from "vue";
 ......
Vue.use(VueRouter);
const routes = [
  {
    path: "/",
    name: "Line",
    component: LineChart,
     },   
  {
    // The redirect can also be targeting a named route:
    path: "/help",
    redirect: { name: 'About' }
  },
  {
    //redirect with aliad
    path: "/doughnut",
    name: "Doughnut",
    component: Doughnut,
    alias: ['/donut', '/dot']

  }, 
];
const router = new VueRouter({
  routes
});

export default router;

In the above router configuration I have a route doughnut which shows the doughnut chart. All I want to different routes set to this route. we redirect /doughnut route to the /donut, /dot routes. As a result all the routes are working

Following vue-route post may interest you

Redirect a route in Vue router


Sometimes we would like to have same route with different name, such guide to FAQ, help, how-to etc. Vue allow us to use the redirect feature for this purpose.

Redirect can be used in our index route file in the following format

import Vue from "vue";
 ......
Vue.use(VueRouter);
const routes = [
  {
    path: "/",
    name: "Line",
    component: LineChart,
     },   
  {
    // The redirect can also be targeting a named route:
    path: "/help",
    redirect: { name: 'About' }
  } 
];
const router = new VueRouter({
  routes
});

export default router;

In the above router configuration we redirect /help router to the named route /About. For multiple route we have to reply on alias.

Following vue-route post may interest you

MobaXterm SSH client for Raspberry pi


May be you are fond of Putty, the SSH client for accessing your Raspberry Pi single board computer. MobXterm can be a replacement for Putty.

It offer the all features offered by Putty and plus we can

MOBAXTERM in Windows 10
  • open multiple terminal,
  • Take screen shot
  • Tunneling
  • Access servers
  • Multiple sessions etc
  • sftp – for accessing folders/file on the remote system (GUI)
  • Remote monitoring

I don’t miss the Putty at all , all those putty sessions are available on MobaXterm.

One of the noticeable feature is that all of Rasp Home folder now accessible from my desktop. I can download and upload file using the sftp.

It allow me to monitor the remote system and MobaXterm will show the memory usage, CPU load etc on the status bar

May be you are looking for these Raspberry pi posts

Linux mastery : pwd


In this series of mini posts I will teach you a Linux lesson every day, it can be command , tricks , how to. The post will cover for beginner to advanced level. Welcome to Linux terminal.

Follow us and start learning Linux today

pwd

pwd is command which return the current working directory. This command is helpful when doing projects and scripting tasks.

Linux : history of command


In this series of mini posts I will teach you a Linux lesson every day, it can be command , tricks , how to etc. The post will cover for beginner to advanced level. Welcome to Linux terminal.

Follow us and start learning Linux today

history

history is a Linux command fetch a list of commands used in terminal. You can specify number of commands want to display

$ history
$ history 5

Following Linux manuals may help you

Linux : accessing the BIOS clock


In this series of mini posts I will teach you a Linux lesson every day, it can be command , tricks , how to etc. The post will cover for beginner to advanced level. Welcome to Linux terminal.

Follow us and start learning Linux today

hwclock

hwclock is a command which provide hardware clock information. Hardware / BIOS clock works even when the system remain in shut down state.

$ sudo apt install locate

Following Linux manuals may help you

Linux : find a file using locate


In this series of mini posts I will teach you a Linux lesson every day, it can be command , tricks , how to etc. The post will cover for beginner to advanced level. Welcome to Linux terminal.

Follow us and start learning Linux today

locate

locate is a command used to find files with specific name, extensions etc in Linux. It also capable of limiting search queries. The command may not available on Linux distributions such as Ubuntu, but can be add using the following command

$ sudo apt install locate

Following Linux manuals may help you

Linux : uptime


In this series of mini posts I will teach you a Linux lesson every day, it can be command , tricks , how to etc. The post will cover for beginner to advanced level. Welcome to Linux terminal.

Follow us and start learning Linux today

uptime

uptime is a Linux command help admins to find how long the system is running, number of users, running state and the load time.

$ w

Following Linux manuals may help you