There are plenty of WordPress plugins that display charts and graphs out there using basic charting tools, but what if you wanted to display data using your own database like MSSQL, MySQL, or PostgreSQL? Don’t worry we got you covered.

Step 1: Build Your Database

Your first step is to of course build your database. To avoid being limited by your WordPress CMS we recommend using a second database that is updated indepdently to handle your large datasets. Your can of course choose any database type you want, however, this guide is for MySQL, MS SQL, and PostgreSQL only.

When building your database you should also determine how you will be populating it with fresh new data to display and have those mechnaisms working before moving on to display your data in a chart or graph.

Step 2: Get the WP Business Intelligence Plugin

Your next step is to make sure you have a plugin that supports using a second database. There is none better than our plugin, WP Business Intelligence Pro for this task. With this plugin you can build all sorts of gorgeous charts and graphs, add captions, and use your own live database. WP Business Intelligence uses shortcodes to easily integrate your charts and graphs into any WordPress page or post.

Not only do you get an amazingly secure and flexible plugin but you also get 1 year of support and a plugin that is constantly being improved.

 
Step 3: Connect Your Database to WP Business Intelligence

Adding a second database to your WP Business Intelligence plugin is super easy. First navigate over to the “Datbase Connections” tab of your plugin. Then click the “Add New” button to start adding your new datbase.

add a database connection to wordpress for charting

Now select your chart type from MySQL/MariaDB, Microsoft SQL Server, or PostgreSQL and fill in the information to create the connection to your SQL database.

connect wordpress to secondary sql database for making a chart

Step 4: Construct an SQL Query
Now we need to build our SQL query to generate the chart or graph. WP Business Intelligence supports only the SELECT statement to ensure your database stays secure.

demo wordpress sql query to make a chart

Step 5: Create Your Chart or Graph
Finally we are going to use the SQL database created and the SQL query we have created to generate a chart or graph to display on a WordPresss website.

To do this you will first go to the tab labeled “Charts” in WP Business Intelligence. Here you will select a chart type to build. In this tutorial we are going to create a bar chart. Once you have selected the chart type you want to create click the “create” button.

sql chart type selection screen

On this screen we are going to select the query we created earlier. Once this is done the chart builder will ask us to select a few more options including giving the chart a name, adding an optional caption, and selecting the data points to display. For a bar chart we need to select two columns of information, one for labeling the bars on our bar chart and one for producing the values (or the height) of each bar.

When you are done creating your chart or graph click the “Save Changes” button and your chart will generate along with a shortcode below.

creating a chart using an sql query in wordpress

Example Chart

Here is an example bar chart made with WP Business Intelligence and an SQL query

This is a caption on a bar chart

Start Creating Charts and Graphs with SQL Queries in WordPress

Start building charts and graphs in WordPress with your own database and SQL queries