Fusioncharts are unable to display any data due to an error

I utilized AJAX to dynamically render the chart. There are two main files involved: index.php and selectchart.php. The index.php file contains the AJAX code to render the chart.

<div class="chart-area">
    <div id="chart-1"><!-- Fusion Charts will render here--></div>
    <div id="chart-mon"><!-- Fusion Charts will render here--></div>

The div with ID chart-1 is used for displaying the annual report, while the chart displayed changes based on the selected month.

</div>

<p><select class="btn btn-light btn-icon-split" id="country" name="country">
<option>--Select Month--</option>
<option value="01">JAN</option>
<option value="02">FEB</option>
<option value="03">MAR</option>
<option value="04">APR</option>
<option value="05">MAY</option>
...
              </select></p>

Javascript

<script type="text/javascript">
    $('#country').change(function() {
        var selectedCountry = $(this).children("option:selected").val();
        
        $.ajax({
            type : "POST",
            url  : "selectchart.php?country="+selectedCountry,
            data : selectedCountry,
            success: function(result) {
                $("#chart-1").hide();
                alert(result);
                
                var myChart = new FusionCharts("column2D", "myThird", 400, 300, "json", result);
                myChart.render("chart-mon");
            }
        });
    });
</script>

When testing, the alert showed [objectoject], but no data was displayed in chart-mon.

Content of selectchart.php:

include("includes/fusioncharts.php"); 

$selectData = $_REQUEST['country'];

$dbHandle = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
if ($dbHandle->connect_error) {
    exit("Connection error: ".$dbHandle->connect_error);
}

$strQueryMon = "SELECT name, amount FROM income WHERE month = '$selectData' ORDER BY amount DESC LIMIT 10";
$resultMon = $dbHandle->query($strQueryMon) or exit("Error code ({$dbHandle->errno}): {$dbHandle->error}");

if ($resultMon) {

    $arrDataMon = array(
        "chart" => array(
          "showValues" => "0",
          "theme" => "zune"
        )
    );

    $arrDataMon["data"] = array();
    while($rowMon = mysqli_fetch_array($resultMon)) {
        array_push($arrDataMon["data"], array(
            "label" => $rowMon["name"],
            "value" => $rowMon["amount"]
        ));
    }

    $jsonEncodedDataMon = json_encode($arrDataMon);

    echo $jsonEncodedDataMon;

    header('Content-type: text/json');
}

Answer №1

Method 1:

I believe there was a mistake in your code:

Instead of:

var myChart = new FusionCharts("column2D", "myChartId" , 400, 300, "json", "result");

You should use:

var myChart = new FusionCharts("column2D", "myChartId" , 400, 300, "json", result);

This is because result (which is a variable) holds the response from your selectchart.php file.

Answer №2

If you encounter a "No data to display" message on your chart, it may be due to the following reasons:

The XML/Json data you are using does not have any information that can be plotted by FusionCharts. This could happen if your XML only contains opening and closing tags without any actual data.

You might be trying to use single-series chart SWF with multi-series data format or vice versa. In such cases, you will see the "No data to display" message.

For certain Dual Y Combination charts, you need to provide data sets for both axes to avoid getting the "No data to display" message.

    <?php
include("includes/fusioncharts.php");

$columnChart = new FusionCharts("column2d", "ex1", "100%", 400, "chart-1", "json", '{
  "chart": {
    "caption": "Countries With Most Oil Reserves [2017-18]",
    "subcaption": "In MMbbl = One Million barrels",
    "xaxisname": "Country",
    "yaxisname": "Reserves (MMbbl)",
    "numbersuffix": "K",
    "theme": "candy"
  },
  "data": [
    {
      "label": "Venezuela",
      "value": "290"
    },
    {
      "label": "Saudi",
      "value": "260"
    },
    {
      "label": "Canada",
      "value": "180"
    },
    {
      "label": "Iran",
      "value": "140"
    },
    {
      "label": "Russia",
      "value": "115"
    },
    {
      "label": "UAE",
      "value": "100"
    },
    {
      "label": "US",
      "value": "30"
    },
    {
      "label": "China",
      "value": "30"
    }
  ]
}');

$columnChart->render();
?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with datepicker initialization causing format not to work in Bootstrap

I am currently incorporating the angular-bootstrap datepicker module into my app and have run into a minor issue. I am using an input text field and a button to display the date in the following manner: <div class="row" id="datePicker"> <p cl ...

Error in Jquery click function not being triggered

I'm in the process of developing an eCommerce platform where users can choose options and have their shopping carts automatically updated using jQuery. Users will be presented with a few radio buttons to select from, and as they make their choice, th ...

selecting a number at random from a defined array

I am looking to generate a series of lottery numbers like the following: my list could be between 1 - 100, or it might range from 1 - 200, or even 1 - 300 select 35 random numbers from the chosen list. choose another set of 25 numbers from the list. pic ...

Issue encountered: Incompatibility between Mongoose Populate and Array.push()

After reading a different post addressing the same issue, I still couldn't figure out how to implement the solution into my own scenario. The discussion revolved around the topic of node js Array.push() not working using mongoose. In my Mongoose asyn ...

Discover how to access the DOM after AngularJS directive rendering is finished

Looking to create a unique scroll pane component using an AngularJS directive? Check out this jsfiddle example for a basic prototype. Here is the concept behind my custom scroll pane: Directice code snippet: myApp.directive('lpScrollPane', ...

Leveraging the power of context to fetch data from a store in a React component within the Next

I'm having trouble with the title in my React project, and I'm new to React and Nextjs. When trying to fetch data from my dummy chat messages, I encountered this error: × TypeError: undefined is not iterable (cannot read property Symbol(Sy ...

How can one use C# and Selenium to send text to a hidden textarea with the attribute style="display: none;"?

I'm encountering an issue where I am unable to write in the textarea using the sendkeys function in Selenium. The specific textarea I am trying to target has an ID of 'txtSkillsTaught-Value' and is located after a script tag that seems to be ...

`Turn nested JSON into a formatted list using jquery`

I am currently facing two challenges: I am having trouble with the HTML structure, as shown in the image below Current HTML structure: https://i.stack.imgur.com/GH46J.png Desired HTML structure: https://i.stack.imgur.com/Dq3Gn.png How can I create d ...

Can a JavaScript class have a property that returns an array?

To those more experienced in node red development, this may be obvious, but I'll ask anyway. Within my node red flow, I have a function node containing a javascript class that only exposes static members. Here's an example: class MeasurementsLis ...

Error: NodeJS is unable to access the property 'name' because it is undefined

I've recently delved into the world of NodeJS with the aim of creating a backend API for a car rental agency. I'm puzzled as to why I'm encountering an error even though I have specified 'name' as a string type and ensured that the ...

I am experiencing an issue with my jQuery ajax where my return function is not working as expected

I'm currently working on the following code snippet: $("#upvote").click(function(){ var up = parseInt(document.getElementById('voteScore').innerHTML); up++; document.getElementById('voteScore').innerHTML = up; $.aj ...

Encountering an error while trying to run a Next.js application on Linux Mint

View the error screenshot After creating a new Next.js app with npx create-next-app, I ran npm run dev and encountered the following error message ...

Tips for managing the extensive amount of JQuery and AJAX code that arises with the implementation of a web API

In my Web Api application, each entity has its own controller class. However, for the main page of the application, I need to perform operations involving multiple entities. To achieve this, I am using jQuery and Ajax calls to interact with the respective ...

Setting the || operator with JSX in React can be done by using the logical OR

Hi, I'm trying to configure two conditional statements using React. Here is the code I have: <div> {item?.status === "One" || (item?.status === "Two" && ( <Button btn="primary" title="One text" /> ))} &l ...

Error encountered: The initMap function from the React Google Maps API is not recognized. No relevant

Encountering an issue where initMap is not recognized as a function. I attempted to avoid utilizing any additional packages for asynchronously loading the script or Google Maps API. My initial approach was to simply console log initMap to track when the sc ...

I'm having trouble understanding why my Javascript validation suddenly stopped functioning. Can anyone assist me in troubleshooting this issue?

I have been working on this webpage for a school project for a few days, and it was running smoothly until about 10 minutes ago. The only change I made was adding an extra JavaScript validation. Now, when I try to register by clicking the "register" butt ...

Applying ng-class based on conditions to icons within table cells

In my table, I am using ng-repeat to bind cells with data. One cell contains edit, save, and delete icons. When an order is posted, the delete/save icons should be disabled and displayed in a different color. While I can disable the click event of the icon ...

Transitioning from AngularJS version 1.5.0 to 1.5.8

My bower.json file contains various dependencies, including AngularJS at version 1.5.0. I am looking to update AngularJS to version 1.5.8 without causing issues for my team members. I attempted to use bower install angular#1.5.8 --save, but this resulted ...

React modal not triggered on click event

As a newcomer to react, I am exploring a modal component import React, { useState, useEffect } from 'react'; import { Modal, Button } from "react-bootstrap"; function TaskModal(props) { return ( <Modal show={pro ...

Assistance needed with converting a Seaside-App to use AJAX (require a template or simple example)

We are facing challenges in ajaxifying our new Seaside-App. The goal of the App is to present contract-data in a cascading view, where contracts' names are displayed at the top level, and clicking on them reveals the "sets" they contain, then clicking ...