Highcharts still unable to display series data despite successful decoding efforts

After receiving JSON decoded data from the server and using $.parseJSON to decode it, I am assigning it to the series in Highcharts. Although there are no console errors, the chart refuses to display.

Below is the code snippet:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="author" content="">
    <title></title>
    <script src="../assets/jquery/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script type="text/javascript">
        parent.$('iframe').height('256');
    </script>
</head>
<body style="overflow:hidden">
<div id="container" style="width:100%; height:400px;"></div>
</div>
<script>

$(function() {
series = [];

series = generateData();

function generateData()
{
   $.ajax({
    url: 'http://exact.offergrid.com/totalVisits.php',
    success: function(data) 
    {
          alert(data);
          ps = [];
          var obj = $.parseJSON(data);
          var len = obj.length;
          //alert(obj.length);
          for (var i = 0; i < len; i++) {
            //alert(obj[i].date+obj[i].count);

            var date = obj[i].date;
            var count = obj[i].count;
            ps[i] = {
                x: date,
                y: count 
            };
            series.push({
                    data: []
            });
            series[i].data.push(ps[i]);
        }
    },      
  });
            return series;
}

$('#container').highcharts({
        chart: {
            renderTo: 'container',
            type: 'column'
        },
        title: {
            text: 'Fruit Consumption'
        },
        xAxis: {

        },
        yAxis: {
            title: {
                text: 'Fruit eaten'
            }
        },
        series: series
});


});
</script>
</body>
</html>

Answer №1

When developing your PHP server-side code to generate chart data, ensure that all values are properly converted to either integers or floats before being added to the chart data array. You can achieve this by using commands like $value = (float)$value; or $value = (int)$value;.

I encountered a similar issue previously, but after implementing this solution, the problem was resolved successfully!

Answer №2

Your PHP results may be returning as strings because your JSON object likely contains non-numeric values. To resolve this issue, try using the parseFloat(obj[i].count) function. Is your data formatted as timestamps?

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

Having trouble retrieving data from the table with AJAX and CodeIgniter

I am currently developing a comprehensive HRM+CRM system (Human Resource Management and Customer Relation Management). I have encountered an issue while trying to generate an invoice for each customer. I am struggling to resolve this problem and would appr ...

Determine the item in a collection of objects that contains a specific key

What is the most efficient method for locating an object by a specific key in JS when given an array of objects? Utilizing jQuery and underscoreJS is acceptable. I am simply seeking the simplest solution with minimal code. Illustration: Suppose we have a ...

The stick division shows some bouncy behavior when seen on a mobile device

When viewing on mobile, the #main-categories div seems to be jumping instead of smoothly sticking to the top. What could be causing this behavior? Here is the code snippet I have: var s = $("#main-categories"); var pos = s.position(); $(window).scroll(f ...

Develop a TypeScript class that includes only a single calculated attribute

Is it advisable to create a class solely for one computed property as a key in order to manage the JSON response? I am faced with an issue where I need to create a blog post. There are 3 variations to choose from: A) Blog Post EN B) Blog Post GER C) Bl ...

Google Chrome is unable to process Jquery JSON .each() function

My website has a simple chat application that is functioning well. It uses ajax to request data in this manner: $.ajax({ url: "fetch/"+CHAT_SESSION_ID+"/"+LAST_MESSAGE_ID, dataType: "json", cache: false, success: function(data) { if (data.session_ac ...

How to Effortlessly Populate Cascading Dropdowns in ASP.Net MVC 5 using a Reusable

I am currently working on an ASP.Net MVC 5 application that has multiple edit pages. Each edit page consists of various input elements such as textboxes, checkboxes, and dropdowns. I want to implement a functionality where the values of one dropdown are ch ...

Spring application: Unable to find a handler for portlet request with mode 'view' and phase 'Resource_PHASE'

It seems like everything is set up correctly, but for some reason, my ajax call fails with the error message "No handler found for portlet request: mode 'view', phase 'Resource_PHASE'". The handler URL I'm using is "getAllFruit", ...

Using jQuery ajax links may either be effective or ineffective, depending on the scenario. At times

Can someone please assist me in understanding why an ajax link may or may not work when clicked? It seems to function intermittently. window.onload = function(){ function getXmlHttp(){ ...... // simply ajax } var contentContainer = ...

What is the best method to compare dates in JavaScript/JQuery to determine if one comes before the other?

I am completely new to JavaScript development and I need to accomplish the task below: I have 2 input tags containing 2 strings representing dates in the format 01/12/2014 (DAY/MONTH/YEAR). These input tags are used to search for objects with a date field ...

Tips for postponing the execution of inline javascript

Main page <script> $.ajax({ type: 'GET', url: 'ajax.php', context: document.body, success: function(data) { $("#content").html(data); } }); </script> <div id="content"></div> Ajax ...

The form submission feature is malfunctioning due to JavaScript issues

I have forms that allow file uploads (images), and I am trying to restrict the size of those images to 500KB. However, for some reason, the forms are not submitting and I am unsure why. Below is the jQuery code: $('form').on('submit', ...

The change event for the select element is malfunctioning

Currently, I am deep diving into Nodejs with the second edition of the node cookbook. This book has caught my attention because it explains concepts using practical sample code, making it easier to grasp. The example code I am working on is related to Br ...

Press the confirm button to halt the AJAX process

I encountered an issue with my code where a CONFIRM message shows up when I click on the A button. However, despite choosing CANCEL, the AJAX request still continues and deletes my record. What could be causing this unexpected behavior? <a href=' ...

Getting a specific piece of information from a JSON file

I am encountering an issue with my JSON file collection. When I access it through http://localhost:5000/product/, I can see the contents without any problem. However, when I try to retrieve a specific product using a link like http://localhost:5000/product ...

Leveraging the power of jQuery with AJAX operations

In my collection of PHP files, I have three named: index page books user Index Page <link href="colorbox.css" type="text/css" rel="stylesheet" media="all" /> <script type="text/javascript" src="jquery-1.8.2.min.js"></script> <scrip ...

What is the best way to interpret this supposedly JSON structure?

I have a large data file in the format below, which is the response from an API call to one of Twitter's APIs. I need to extract the "followers_count" field value from it. Typically, I would use jq with the command: cat | jq -r '.followers_count ...

jQuery modal does not open when dynamic buttons are clicked

I am currently working on a tabbed panel that contains Datatables lists with buttons for editing or removing each row in the tables. The issue I am facing is that only the edit actions button in the first pane works correctly, while the buttons in the othe ...

The horizontal overflow in the HTML code was unsuccessful

I stumbled upon an interesting issue where I applied a div with specific styling: overflow-x: scroll However, the outcome was not as expected. Instead of overflowing, the content simply started on a new line. Here is the source code for reference: & ...

Troubleshooting: Node.js Express Server GET Handler Failing to Function

Recently, I've been attempting to build a GET request handler in Express.js. Here's the snippet of code I've put together: // include necessary files and packages const express = require('./data.json'); var app = express(); var m ...

Check the row in a JQuery table by using the .on("click") function to determine if a hyperlink within the row was clicked or if

I am in the process of building a website using the following libraries: Parse.js: 1.4.2 JQuery: 1.11.2 and 1.10.3 (U.I.) Twitter Bootstrap: 3.3.4 To demonstrate what I am trying to achieve, I have set up this JSfiddle with placeholder data: https://jsf ...