{"id":16361,"date":"2017-10-12T19:57:08","date_gmt":"2017-10-12T14:27:08","guid":{"rendered":"http:\/\/www.fusioncharts.com\/blog\/?p=16361"},"modified":"2026-01-20T14:36:35","modified_gmt":"2026-01-20T09:06:35","slug":"creating-charts-using-php-mongodb","status":"publish","type":"post","link":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/","title":{"rendered":"How to Create Charts in PHP by Fetching Data from MongoDB 2026"},"content":{"rendered":"Most enterprise apps currently use relational databases like SQL, MariaDB, or MySQL due to their popularity and stable nature. However, developers face issues when they try to scale such databases. Furthermore, considering the recent breed of web applications that handle large data sets, developers are constantly looking for more scalable databases. This has attributed to the rise of non-relational (NoSQL) databases. One such database that has become really popular is MongoDB.\r\n\r\nIn this tutorial we will follow a step-by-step approach to create charts using data stored in a MongoDB database. We will use the PHP scripting language to connect to the database and fetch the data, which would then be used to render the chart.\r\n\r\nWe picked PHP over others as it comes with a MongoDB driver that connects it to the database. If you need to add more firepower to your web application, you can also use Node.js.\r\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#Requirements\" title=\"Requirements:\u00a0\">Requirements:\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#Part_1_Including_Dependencies\" title=\"Part 1: Including Dependencies\">Part 1: Including Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#Part_2_Establishing_and_Validating_Database_Connection\" title=\"Part 2: Establishing and Validating Database Connection\">Part 2: Establishing and Validating Database Connection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#Part_3_Rendering_the_Chart\" title=\"Part 3: Rendering the Chart\">Part 3: Rendering the Chart<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Requirements\"><\/span><strong>Requirements:\u00a0<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\nFor creating charts using PHP and MongoDB, you need the following to be downloaded and installed on your system:\r\n<ul>\r\n \t<li>XAMPP<\/li>\r\n \t<li>MongoDB<\/li>\r\n \t<li>PHP driver for MongoDB<\/li>\r\n \t<li>Composer<\/li>\r\n<\/ul>\r\n<h2><span class=\"ez-toc-section\" id=\"Part_1_Including_Dependencies\"><\/span>Part 1: Including Dependencies<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\nTo render FusionCharts in PHP using MongoDB, we need to include following dependencies:\r\n<ul>\r\n \t<li>FusionCharts Suite XT: To begin, you need to download the <a href=\"https:\/\/www.fusioncharts.com\/download\/\">FusionCharts Suite XT package <\/a>and store all the extracted script files in a new folder inside the project folder, as shown below.<\/li>\r\n<\/ul>\r\n<pre class=\"lang:markup decode:true\" title=\"Including FusionCharts core package JS files\">&lt;html&gt;\r\n   &lt;head&gt;\r\n      &lt;script src=\"path-to\/fusioncharts.js\"&gt;&lt;\/script&gt;\r\n      &lt;script src=\"path-to\/fusioncharts.theme.fint.js\"&gt;&lt;\/script&gt;\r\n   &lt;\/head&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\r\n<ul>\r\n \t<li>FusionCharts PHP Wrapper: Extract the\u00a0<a href=\"https:\/\/www.fusioncharts.com\/php-charts\/\" target=\"_blank\" rel=\"noopener noreferrer\">FusionCharts PHP Wrapper\u00a0<\/a>\u00a0and save the\u00a0<code>fusioncharts.php<\/code>\u00a0file inside the same folder created in the previous step for keeping the script files.<\/li>\r\n<\/ul>\r\n<pre class=\"lang:php decode:true\" title=\"Including FusionCharts PHP wrapper\">&lt;?php\r\n    require 'fusioncharts\/fusioncharts.php';\r\n?&gt;\r\n<\/pre>\r\n<ul>\r\n \t<li>PHP Library for MongoDB (<a href=\"https:\/\/php.net\/manual\/en\/mongodb.tutorial.library.php\" target=\"_blank\" rel=\"noopener noreferrer\">Details\u00a0<\/a>): Include the\u00a0<code>autoload.php<\/code>\u00a0file that is required for using MongoDB with PHP.<\/li>\r\n<\/ul>\r\n<pre class=\"lang:php decode:true \">&lt;?php\r\n    require 'vendor\\autoload.php';\r\n?&gt;<\/pre>\r\n<h2><span class=\"ez-toc-section\" id=\"Part_2_Establishing_and_Validating_Database_Connection\"><\/span>Part 2: Establishing and Validating Database Connection<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\nOnce the dependencies are included in our code, we now establish the connection with our database to fetch data for the chart.\r\n<pre class=\"lang:php decode:true \" title=\"Validating DB connection\">&lt;?php\r\n$dbconn = new MongoDB\\Client;\r\n\r\nif(!$dbconn) {\r\n   exit(\"There was an error establishing database connection\");\r\n}\r\n?&gt;\r\n<\/pre>\r\n<h2><span class=\"ez-toc-section\" id=\"Part_3_Rendering_the_Chart\"><\/span>Part 3: Rendering the Chart<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\nNow that we have established the connection to our database, we will fetch data for our chart.\r\n\r\nLet us now look at\u00a0our\u00a0<code>chartData<\/code>\u00a0collection in the\u00a0<code>myProject<\/code>\u00a0database which we will be using to render the chart.\r\n\r\n<a href=\"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-16362\" src=\"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-database.png\" alt=\"\" width=\"525\" height=\"172\" srcset=\"\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-database.png 525w, \/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-database-150x49.png 150w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a>\r\n\r\nThe PHP code for fetching data from our database is as given below:\r\n<pre class=\"lang:php decode:true \" title=\"Retrieving data from the database\">$db = $dbconn-&gt;myProject;\r\n$myObj = $db-&gt;chartData-&gt;find();\r\n\r\n\/\/convert MongoCursor into an array\r\n$data=iterator_to_array($myObj);\r\n\r\n\/\/ sorting the data\r\nasort($data);\r\n<\/pre>\r\nNext, we will use\u00a0<code>$data<\/code>\u00a0to hold the data fetched from our database. We will now form an associative JSON array for the chart.\r\n\r\nFusionCharts accepts both XML and JSON data formats. Since we will be using JSON, we will now append the data (fetched from database in the\u00a0<code>$data<\/code>\u00a0variable) along with FusionCharts chart configuration and parse the end result as an associative JSON array.\r\n\r\nThe PHP code required to append the chart data fetched from the database is given below:\r\n<pre class=\"lang:php decode:true \">if ($data) { \r\n\t\r\n\t$categoryArray=array();\r\n\t\r\n\t$dataseries1=array(); \r\n\t\r\n\t$dataseries2=array(); \r\n\t\r\n\tforeach ($data as $dataset) {\r\n\t \r\n\t\tarray_push($categoryArray, array( \r\n\t\t\"label\" =&gt; $dataset[\"month\"] \r\n\t\t)); \r\n\r\n\t\tarray_push($dataseries1, array( \r\n\t\t\"value\" =&gt; $dataset[\"petrol\"] \r\n\t\t)); \r\n\r\n\t\tarray_push($dataseries2, array( \r\n\t\t\"value\" =&gt; $dataset[\"diesel\"] \r\n\t\t)); \r\n\t} \r\n\r\n\t$arrData = array( \r\n\t\t\"chart\" =&gt; array( \r\n\t\t\t\"caption\"=&gt; \"Comparison of Petrol and Diesel price\", \r\n\t\t\t\"xAxisname\"=&gt;\"Month\", \r\n\t\t\t\"yAxisname\"=&gt;\"Price\", \r\n\t\t\t\"numberPrefix\"=&gt;\"$\", \r\n\t\t\t\"paletteColors\"=&gt; \"#876EA1, #72D7B2\", \r\n\t\t\t\"useplotgradientcolor\"=&gt; \"0\", \r\n\t\t\t\"plotBorderAlpha\"=&gt; \"0\", \r\n\t\t\t\"bgColor\"=&gt; \"#FFFFFFF\", \r\n\t\t\t\"canvasBgColor\"=&gt; \"#FFFFFF\", \r\n\t\t\t\"showValues\"=&gt; \"0\", \r\n\t\t\t\"showCanvasBorder\"=&gt; \"0\", \r\n\t\t\t\"showBorder\"=&gt; \"0\", \r\n\t\t\t\"divLineAlpha\"=&gt; \"40\", \r\n\t\t\t\"divLineColor\"=&gt; \"#DCDCDC\", \r\n\t\t\t\"alternateHGridColor\"=&gt; \"#DCDCDC\", \r\n\t\t\t\"alternateHGridAlpha\"=&gt; \"15\", \r\n\t\t\t\"labelDisplay\"=&gt; \"auto\", \r\n\t\t\t\"baseFont\"=&gt; \"Assistant\", \r\n\t\t\t\"baseFontColor\"=&gt; \"#000000\", \r\n\t\t\t\"outCnvBaseFont\"=&gt; \"Assistant\", \r\n\t\t\t\"outCnvBaseFontColor\"=&gt; \"#000000\", \r\n\t\t\t\"baseFontSize\"=&gt; \"13\", \r\n\t\t\t\"outCnvBaseFontSize\"=&gt; \"13\", \r\n\t\t\t\"labelFontColor\"=&gt; \"#000000\", \r\n\t\t\t\"captionFontColor\"=&gt; \"#153957\", \r\n\t\t\t\"captionFontBold\"=&gt; \"1\", \r\n\t\t\t\"captionFontSize\"=&gt; \"20\", \r\n\t\t\t\"subCaptionFontColor\"=&gt; \"#153957\", \r\n\t\t\t\"subCaptionfontSize\"=&gt; \"17\", \r\n\t\t\t\"subCaptionFontBold\"=&gt; \"0\", \r\n\t\t\t\"captionPadding\"=&gt; \"20\", \r\n\t\t\t\"valueFontBold\"=&gt; \"0\", \r\n\t\t\t\"showAxisLines\"=&gt; \"1\", \r\n\t\t\t\"yAxisLineColor\"=&gt; \"#DCDCDC\", \r\n\t\t\t\"xAxisLineColor\"=&gt; \"#DCDCDC\", \r\n\t\t\t\"xAxisLineAlpha\"=&gt; \"15\", \r\n\t\t\t\"yAxisLineAlpha\"=&gt; \"15\", \r\n\t\t\t\"toolTipPadding\"=&gt; \"7\", \r\n\t\t\t\"toolTipBorderColor\"=&gt; \"#DCDCDC\", \r\n\t\t\t\"toolTipBorderThickness\"=&gt; \"0\", \r\n\t\t\t\"toolTipBorderRadius\"=&gt; \"2\", \r\n\t\t\t\"showShadow\"=&gt; \"0\", \r\n\t\t\t\"toolTipBgColor\"=&gt; \"#153957\", \r\n\t\t\t\"toolTipBgAlpha\"=&gt; \"90\", \r\n\t\t\t\"toolTipColor\"=&gt; \"#FFFFFF\", \r\n\t\t\t\"legendBorderAlpha\"=&gt; \"0\", \r\n\t\t\t\"legendShadow\"=&gt; \"0\", \r\n\t\t\t\"legendItemFontSize\"=&gt; \"14\" \r\n\t\t) \r\n\t); \r\n\r\n\t$arrData[\"categories\"]=array(array(\"category\"=&gt;$categoryArray)); \r\n\r\n\t\/\/ creating dataset object \r\n\t$arrData[\"dataset\"] = array(array(\"seriesName\"=&gt; \"Petrol_price\", \"data\"=&gt;$dataseries1), array(\"seriesName\"=&gt; \"Diesel_price\", \"data\"=&gt;$dataseries2)); \r\n\r\n\t$jsonEncodedData = json_encode($arrData); \r\n}<\/pre>\r\nEvery chart displayed on a web page is rendered within a unique HTML container. We will be using the\u00a0<code>&lt;div&gt;<\/code>\u00a0element for creating the HTML container for our chart.\r\n\r\nGiven below is the code for creating the chart container:\r\n<pre class=\"lang:markup decode:true \">&lt;body&gt;\r\n   &lt;div id=\"chart-container\"&gt;Fusion Charts will render here&lt;\/div&gt; \r\n&lt;\/body&gt;<\/pre>\r\nNow that we have the JSON data and chart container in place, we will create the FusionCharts instance and call the <code>render()<\/code> method to render the chart.\r\n\r\nChart instance includes details needed to render the chart, like the chart type, chart ID, chart dimensions, the HTML container ID, and so on, will be passed to this chart instance.\r\n<pre class=\"lang:php decode:true \">$msChart = new FusionCharts(\"msline\", \"demochart\", \"600\", \"400\", \"chart-container\", \"json\", $jsonEncodedData); \r\n$msChart-&gt;render();\r\n<\/pre>\r\nIf you have been closely following the above steps, then you should see a chart like the image shown below:\r\n\r\n<a href=\"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-16363\" src=\"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-output.png\" alt=\"\" width=\"1192\" height=\"794\" srcset=\"\/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-output.png 1192w, \/blog\/wp-content\/uploads\/2017\/10\/creating-charts-php-mongodb-output-150x100.png 150w\" sizes=\"auto, (max-width: 1192px) 100vw, 1192px\" \/><\/a>\r\n\r\nIf you are still having trouble rendering the chart, you can view the source code in the Github repo. The article first appeared <a href=\"https:\/\/www.pluralsight.com\/guides\/php\/create-charts-using-php-and-mongodb?status=in-review\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.","protected":false},"excerpt":{"rendered":"<p>Most enterprise apps currently use relational databases like SQL, MariaDB, or MySQL due to their popularity and stable nature. However, developers face issues when they try to scale such databases. Furthermore, considering the recent breed of web applications that handle large data sets, developers are constantly looking for more scalable databases. This has attributed to [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":16370,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"coauthors":[653,688],"class_list":["post-16361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Create Charts In PHP By Fetching Data From MongoDB<\/title>\n<meta name=\"description\" content=\"Build strikingly beautiful PHP charts with MongoDB. Use our 2026 guide to master NoSQL data visualization for your web applications. Try this tutorial today.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Create Charts In PHP By Fetching Data From MongoDB\" \/>\n<meta property=\"og:description\" content=\"NoSQL databases are a boon when it comes to scalability. Learn all the steps to build strikingly beautiful charts in PHP using data coming from MongoDB.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"FusionBrew - The FusionCharts Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-12T14:27:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-20T09:06:35+00:00\" \/>\n<meta name=\"author\" content=\"Prerana Singh, Gagan Sikri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prerana Singh, Gagan Sikri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\/\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"Article\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Prerana Singh\",\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/d160bebbc408a11542797e038733b9ce\"\n\t            },\n\t            \"headline\": \"How to Create Charts in PHP by Fetching Data from MongoDB 2026\",\n\t            \"datePublished\": \"2017-10-12T14:27:08+00:00\",\n\t            \"dateModified\": \"2026-01-20T09:06:35+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\"\n\t            },\n\t            \"wordCount\": 578,\n\t            \"commentCount\": 1,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png\",\n\t            \"articleSection\": [\n\t                \"Tutorials\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\",\n\t            \"url\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\",\n\t            \"name\": \"How To Create Charts In PHP By Fetching Data From MongoDB\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png\",\n\t            \"datePublished\": \"2017-10-12T14:27:08+00:00\",\n\t            \"dateModified\": \"2026-01-20T09:06:35+00:00\",\n\t            \"description\": \"Build strikingly beautiful PHP charts with MongoDB. Use our 2026 guide to master NoSQL data visualization for your web applications. Try this tutorial today.\",\n\t            \"breadcrumb\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#breadcrumb\"\n\t            },\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage\",\n\t            \"url\": \"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png\",\n\t            \"contentUrl\": \"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png\",\n\t            \"width\": 2016,\n\t            \"height\": 750,\n\t            \"caption\": \"charting in php and mongoDB\"\n\t        },\n\t        {\n\t            \"@type\": \"BreadcrumbList\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#breadcrumb\",\n\t            \"itemListElement\": [\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 1,\n\t                    \"name\": \"Home\",\n\t                    \"item\": \"https:\/\/www.fusioncharts.com\/blog\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 2,\n\t                    \"name\": \"How to Create Charts in PHP by Fetching Data from MongoDB 2026\"\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#website\",\n\t            \"url\": \"https:\/\/www.fusioncharts.com\/blog\/\",\n\t            \"name\": \"FusionBrew - The FusionCharts Blog\",\n\t            \"description\": \"Get tips and tricks on how to build effective Data Visualisation using FusionCharts\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\/\/www.fusioncharts.com\/blog\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#organization\",\n\t            \"name\": \"FusionCharts\",\n\t            \"url\": \"https:\/\/www.fusioncharts.com\/blog\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/logo\/image\/\",\n\t                \"url\": \"\/blog\/wp-content\/uploads\/2020\/03\/idera-fc-logo.svg\",\n\t                \"contentUrl\": \"\/blog\/wp-content\/uploads\/2020\/03\/idera-fc-logo.svg\",\n\t                \"width\": 1,\n\t                \"height\": 1,\n\t                \"caption\": \"FusionCharts\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/logo\/image\/\"\n\t            }\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/d160bebbc408a11542797e038733b9ce\",\n\t            \"name\": \"Prerana Singh\",\n\t            \"image\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/image\/c3a2501c113e420c92343a5caf1ccc58\",\n\t                \"url\": \"\/blog\/wp-content\/wphb-cache\/gravatar\/883\/8839d500f92b36cec1f99073ef09cf90x96.jpg\",\n\t                \"contentUrl\": \"\/blog\/wp-content\/wphb-cache\/gravatar\/883\/8839d500f92b36cec1f99073ef09cf90x96.jpg\",\n\t                \"caption\": \"Prerana Singh\"\n\t            },\n\t            \"url\": \"https:\/\/www.fusioncharts.com\/blog\/author\/prerana-singh\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Create Charts In PHP By Fetching Data From MongoDB","description":"Build strikingly beautiful PHP charts with MongoDB. Use our 2026 guide to master NoSQL data visualization for your web applications. Try this tutorial today.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/","og_locale":"en_US","og_type":"article","og_title":"How To Create Charts In PHP By Fetching Data From MongoDB","og_description":"NoSQL databases are a boon when it comes to scalability. Learn all the steps to build strikingly beautiful charts in PHP using data coming from MongoDB.","og_url":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/","og_site_name":"FusionBrew - The FusionCharts Blog","article_published_time":"2017-10-12T14:27:08+00:00","article_modified_time":"2026-01-20T09:06:35+00:00","author":"Prerana Singh, Gagan Sikri","twitter_card":"summary_large_image","twitter_image":"https:\/\/www.fusioncharts.com\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png","twitter_misc":{"Written by":"Prerana Singh, Gagan Sikri","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#article","isPartOf":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/"},"author":{"name":"Prerana Singh","@id":"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/d160bebbc408a11542797e038733b9ce"},"headline":"How to Create Charts in PHP by Fetching Data from MongoDB 2026","datePublished":"2017-10-12T14:27:08+00:00","dateModified":"2026-01-20T09:06:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/"},"wordCount":578,"commentCount":1,"publisher":{"@id":"https:\/\/www.fusioncharts.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage"},"thumbnailUrl":"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/","url":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/","name":"How To Create Charts In PHP By Fetching Data From MongoDB","isPartOf":{"@id":"https:\/\/www.fusioncharts.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage"},"image":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage"},"thumbnailUrl":"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png","datePublished":"2017-10-12T14:27:08+00:00","dateModified":"2026-01-20T09:06:35+00:00","description":"Build strikingly beautiful PHP charts with MongoDB. Use our 2026 guide to master NoSQL data visualization for your web applications. Try this tutorial today.","breadcrumb":{"@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#primaryimage","url":"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png","contentUrl":"\/blog\/wp-content\/uploads\/2017\/10\/blog-1.png","width":2016,"height":750,"caption":"charting in php and mongoDB"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fusioncharts.com\/blog\/creating-charts-using-php-mongodb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fusioncharts.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Charts in PHP by Fetching Data from MongoDB 2026"}]},{"@type":"WebSite","@id":"https:\/\/www.fusioncharts.com\/blog\/#website","url":"https:\/\/www.fusioncharts.com\/blog\/","name":"FusionBrew - The FusionCharts Blog","description":"Get tips and tricks on how to build effective Data Visualisation using FusionCharts","publisher":{"@id":"https:\/\/www.fusioncharts.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.fusioncharts.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.fusioncharts.com\/blog\/#organization","name":"FusionCharts","url":"https:\/\/www.fusioncharts.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/logo\/image\/","url":"\/blog\/wp-content\/uploads\/2020\/03\/idera-fc-logo.svg","contentUrl":"\/blog\/wp-content\/uploads\/2020\/03\/idera-fc-logo.svg","width":1,"height":1,"caption":"FusionCharts"},"image":{"@id":"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/d160bebbc408a11542797e038733b9ce","name":"Prerana Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fusioncharts.com\/blog\/#\/schema\/person\/image\/c3a2501c113e420c92343a5caf1ccc58","url":"\/blog\/wp-content\/wphb-cache\/gravatar\/883\/8839d500f92b36cec1f99073ef09cf90x96.jpg","contentUrl":"\/blog\/wp-content\/wphb-cache\/gravatar\/883\/8839d500f92b36cec1f99073ef09cf90x96.jpg","caption":"Prerana Singh"},"url":"https:\/\/www.fusioncharts.com\/blog\/author\/prerana-singh\/"}]}},"_links":{"self":[{"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/posts\/16361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/comments?post=16361"}],"version-history":[{"count":0,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/posts\/16361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/media\/16370"}],"wp:attachment":[{"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/media?parent=16361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/categories?post=16361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/tags?post=16361"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.fusioncharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=16361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}