There are a couple of popular front-end frameworks today. We recently covered how to build an analytics dashboard with React and Angular. What both of these guides share is Cube—an open-source analytics framework, which powers these dashboards with high-performance data. Being open-source, Cube is open to contributions, and you can find a contribution guide in the repository on Github. One of the latest contributions from the community is a Cube.js client for Vue. It was built by Ricardo Tapia from Qualibrate and he's got a great blog post about that process. In this tutorial, I'll touch on some details and provide a step-by-step guide on building your own analytics dashboard with Vue.
Setting up a Cube Backend
We covered this topic in other tutorials, so if you already have your Cube backend set up and running, you can skip this section.
You can install Cube CLI, which is used for various Cube workflows, via NPM or Yarn.
Let's prepare a Cube Backend to serve data for the dashboard we're building. Cube supports many databases and deployment options. You can learn more about it in the documentation. For this tutorial, we’ll use a Postgres database and deploy Cube to Heroku. Let's create a new Cube application using the CLI we just installed.
In case you don't have a database for the dashboard yet, you can download our demo e-commerce dataset for Postgres.
The next step is to define a data model. In a production application, you most likely will have multiple schema files, but for our demo app we are going to have only one cube. If you're not familiar with Cube.js data schema, there's an in-depth tutorial here.
Cube.js uses data schema to generate and execute SQL in the connected database. We can test it out by sending a sample request to the Cube REST API endpoint.
You can learn more about the Cube.js Query format here.
Finally, let’s deploy our backend to Heroku:
You can find full deployment guide in the documentation.
Create Vue App
When the backend is up and running, it's time to build the dashboard. Since we're using Vue, the best way to create a new app is by using
First, install vue-cli if you don't have it already:
To create an app, you can use your terminal or start a tool called Vue UI:
This will run a website on your computer, which allows you to create apps, run, and monitor them. It also contains all links to documentation and other community resources.
To create an app using the terminal, all you need is a name:
You can configure plugins for your application, but for the demo we'll use the default setup.
If you created the app using Vue UI, you can start it right there. If you're using the console, run the
Now your application is running on your computer and is accessible via the browser.
Setting up the dashboard
First, we'll add some basic styles using Bootstrap. We'll install it from the CDN, but you can add it using npm or yarn. Open your
public/index.html file and add Bootstrap resources:
Now when bootstrap is installed, we can create some basic structure for the app:
Now we need some data to show. There's a full documentation for the Cube Vue client where you can find additional options. First, we need to set up a Cube instance with our backend URL and API token:
Now let's set up our app to use a QueryBuilder component and create a query counting all users:
The Cube Vue Client allows child components to receive a resultSet object for a given query. Let's create a new component called
What we need here is to display a loading element while data is loading and show a number after. Let's get back to our
App.vue component and create a first tile:
To create a chart, we'll use the Laue library. It's pretty simple and has a great collection of examples online. First, we'll install Laue in our application:
This allows us to use all Laue items in any component. There are other installation methods in the documentation. Now let's create a LineChart component:
To render chart, we'll use a type prop on our Chart component. Let's add a conditional render there:
Now our LineChart component is done! What we need now is to add a query for the line chart in our App.vue component:
That's it for the line chart. The setup for the bar chart is pretty similar.