Skip to main content

How to create charts using the quickchart API

Pie chart


This tutorial covers how to create various types of charts using the quickchart api in Sketchware.

Quickchart

QuickChart is an API for generating static bar charts, pie charts, line charts and more. It's free to use but has a limit of 1 chart per second on the public service. 

You can use the quickchart API to display charts in your Sketchware app and I will show you how.

We will start by building our layout then adding our logic. I will also show you how to make variations to the logic.

Let's get started

Building the layout

Let's start by adding an image to our layout. I set my linear width and height to match parent.

Add full screen imageview


Setting up the logic

I will place my logic onStart but depending on your needs, you can place it on another event such as onButtonClick.

So I navigate to my onCreate event and use the following block to set the image from a url

set image from url block

Pie Chart

Inside the set image from url block, add the following code.

https://quickchart.io/chart?c={type:'pie',data:{labels:['Sales','Purchases','Gross Profit','Expenses','Net Profit'], datasets:[{data:[50,60,70,180,190]}]}}


To understand the code above note the corresponding color coded explanation below.

• 'pie' is the type of chart

'labels' are the names of our values. In the above example we have Sales, Purchases, Gross Profit, Expenses and Net Profit.

• 'data' is the numeric values that we want to display in chart format.

Pie chart logic in onCreate

Alternative logic

If you want your users to enter their own data, you can replace the labels and data fields in your logic with edittext blocks. Use the method shown below:


chart logic with edittexts

I used the join blocks shown below. 

Join block

Remember not to leave any blank space since this is a url.

Once we have set up our logic we can now run our app. It will display a pie chart as shown below:

Pie chart in Sketchware


Bar chart

We can create a bar chart by simply altering our code above and changing the type to 'bar' chart as highlighted below:

https://quickchart.io/chart?c={type:'bar',data:{labels:['Sales','Purchases','Gross Profit','Expenses','Net Profit'], datasets:[{data:[50,60,70,180,190]}]}}

This code will create a bar chart like the one below:


Bar chart in Sketchware


Line chart

We can create a line chart by simply altering our code above and changing the type to 'line' chart as highlighted below:

https://quickchart.io/chart?c={type:'line',data:{labels:['Sales','Purchases','Gross Profit','Expenses','Net Profit'], datasets:[{data:[50,60,70,180,190]}]}}

This code will create a line chart like the one below:


line chart in Sketchware


Conclusion

Using the Quickchart API you can create and display charts in your app. This is particularly useful for displaying reports and any other data in visual format. You can easily adapt the logic to suit your own specific needs.


Comments

Sunny Hassan said…
How to change the color

Popular posts from this blog

How to easily create background notifications in Sketchware(original)

How to easily create background notifications in Sketchware(original) One of the keys to building a successful app is to find mechanisms that will keep your users engaged. You can do this by using background notifications. This tutorial will show you how to do that in Sketchware. We will cover: 1. How to create notifications in Sketchware 2. How to show these notifications even when the app is closed.

How I got started with Sketchware

Background As I explored the Playstore sometime in June 2018, I stumbled upon an app to create other apps. Out of curiosity I downloaded it, did some research and played around with it. I soon realised I could actually create a “real” app from scratch and make money. See, some years earlier I had downloaded Android studio and done a few lessons on programming. So I had a basic understanding of Java and android programming, but this new app that I had found, used simple drag and drop features and you could actually run the app on your device or send your app to friends in just a few clicks. I was not a professional programmer but using this app I could easily create “proper” mobile apps without cracking my head over code.  You can check out my app made using Sketchware; Business Builder- Small Business Management Suite here . Fast forward to a few months later and I had created an app that I felt was ready for the big leagues… Play Store baby!! Note, that I was at a low point f...

Happy Birthday Memes: Laugh Your Way to Someone's Heart

Happy Birthday Memes: Laugh Your Way to Someone's Heart Introduction Birthdays are a special occasion to celebrate another year of life, and what better way to do it than with a good laugh? That's where happy birthday memes come in! These hilarious images are the perfect way to put a smile on someone's face and let them know you're thinking of them on their special day.