The pie chart in HighChart is not showing any data

A visual representation of the data is shown below using a Pie Chart:

https://i.sstatic.net/yDtYm.png

The data is stored in JSON format, you can access it here.

EDIT

Here's the console output:

https://i.sstatic.net/kAvRx.png

When I experimented with "bar" or "column" chart types, everything functioned properly.

I'm still learning about this, any assistance from fellow users would be greatly appreciated!

Django version: 1.10
Python version: 3.6


chartViewHigh.html

{% block main %}

    <h1 align="center">Analysis</h1>


{% block content %}

    <div id="container" style="width:50%; height:400px;"></div>

{% endblock %}

{% block extrajs %}
<script>
   var endpoint = '/api/chart/data/';

   var labels = [];
   var defaultData = [];
   var labels2 = [];
   var defaultData2 = [];

   $.ajax({
      method: "GET",
      url: endpoint,
       /**
        * @param data
        * @param data.labels   
        * @param data.default
        * @param data.default2
       */
       success: function (data) {
            labels = data.labels;
            defaultData = data.default;
            labels2 = data.labels2;
            defaultData2 = data.default2;
            setChart()
        },
        error: function (error_data) {
            console.log("error");
            console.log(error_data)
        }
    });

    function setChart() {
            $(document).ready(function() {
                var chartOptions = {
                     plotBackgroundColor: null,
                     plotBorderWidth: null,
                     plotShadow: false
                };
                var title = {
                     text: 'Total'
                 };
                var tooltip = {
                     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                  };
                var seriesOptions = {
                     pie: {
                         allowPointSelect: true,
                         cursor: 'pointer',
                     dataLabels: {
                         enabled: true,
                         format: '<b>{point.name}%</b>: {point.percentage:.1f} %',
                          style: {
                              color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                          }
                     }
                }
            };
            var seriesData= [{
               type: 'pie',
               name: 'Group share',
               data: [
                   { name: 'Board',   y: defaultData },
                  {
                     name: 'Member',
                     y: defaultData2,
                     sliced: true,
                     selected: true
                  }
               ]
            }];

            var jsonData = {};
            jsonData.chart = chartOptions;
            jsonData.title = title;
            jsonData.tooltip = tooltip;
            jsonData.series = seriesData;
            jsonData.plotOptions = seriesOptions;
            $('#container').highcharts(jsonData);
         });

views.py

 class ChartData(APIView):
     def get(self, request, format=None):
        qs_count = Administrator.objects.filter(association=self.request.user.association).count()
        qs_count2 = Member.objects.filter(association=self.request.user.association).count()

        labels = ["Members"]
        default_items = [qs_count2]
        labels2 = ["Board"]
        default_items2 = [qs_count]

        data = {
           "labels": labels,
           "default": default_items,
           "labels2": labels2,
           "default2": default_items2
        }
        return Response(data)

Answer №1

The format of the data array is incorrect. Please ensure that the y values are numbers and not arrays.

To correct this, update the series variable as follows:

 var series= [{
           type: 'pie',
           name: 'Group share',
           data: [{ 
       name: 'Board',   
       y: defaultData[0] },
              {
                 name: 'Member',
                 y: defaultData2[0],
                 sliced: true,
                 selected: true
              }
           ]
        }];

Alternatively, you can send those values as single numbers instead of arrays.

Answer №2

It appears that the chart section of your code is missing a declaration for a pie chart.

           var chart = {
                 plotBackgroundColor: null,
                 plotBorderWidth: null,
                 plotShadow: false,
                 type: 'pie' // don't forget this line.
            };

I haven't had a chance to run your code yet, but hopefully adding this will resolve the issue.

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

Is it possible to debug JavaScript functions using Visual Studio?

I'm intrigued about debugging javascript functions in Visual Studio. If it's feasible, kindly share with me the process. I am currently involved in an asp.net web application project. ...

What is the best way to show the probability of users' bets in percentage form based on their wagered amounts?

I am currently working on creating a Jackpot Roulette game that features a main pot. Each round sees users joining and placing bets that contribute to the main pot, with the winner taking home the entire amount. My goal is to provide each user with real-t ...

Performing a search query excluding certain criteria

Seeking assistance with a complex query where I need to exclude items based on specific conditions. To illustrate, consider the following simplified model: class Thing(models.Model) user = models.ForeignKey(User) shared = models.BooleanField() ...

Trigger a React event using D3.js dispatch

While working with my axis, I encountered an issue when trying to dispatch a React event along with a payload. What I noticed was that when I used console.log('item'), a pointer event was being logged instead of the expected item property. Is thi ...

Implementing image display in autocomplete feature using jQuery

I am currently working on a project using Spring MVC, where I am implementing a jQuery autocomplete plugin to fetch data from a JSON file generated by the server. $('#searchTerm').autocomplete({ serviceUrl: '${ctx}/search/searchAutocomp ...

Using JavaScript to create a dynamic to-do list that persists on the browser even when refreshed

I created a Javascript Todolist that is functioning well, but I am seeking a way to ensure that my Todo-items persist on the browser even after refreshing until I choose to delete them. Any suggestions or advice on how I can achieve this? ...

Using jQuery setTimeout within a forEach loop

Currently, I am fetching an array of messages using 'getJSON method. My intention is to display each message for 3 seconds before moving on to the next one. The process involves loading an HTML file and applying a CSS class to each message. However, m ...

Formik integration issue with MUI DatePicker causing error message: "date.isBefore is not a function"

I'm currently creating a form in React using Formik and MUI components. However, I encountered an error that says: date.isBefore is not a function TypeError: date.isBefore is not a function at DayjsUtils.isBeforeDay (http://localhost:3000/static/j ...

Encountering a 500 error in API Connect while trying to incorporate basic Javascript functionality

Currently, I am following some basic API Connect tutorials on IBM's platform. I am running these tutorials locally using Loopback, but I have hit a roadblock at an early stage. Initially, I created a simple API service with some in-memory data and se ...

modify the sequence in which celery workers carry out tasks from the queue

Currently, I am incorporating celery with django for my project. The setup involves several producers pushing tasks into a single queue that is then handled by multiple workers. As per Celery's default configuration, the execution order of the queue f ...

Exploring the depths of a JSON structure using jQuery

This is my first time working with JSON data and I need some guidance on a specific issue. When using .getJSON on a local file, the structure appears neat like this: https://i.sstatic.net/7CYPC.jpg I can easily retrieve the value I want (CustRep) with c ...

Sending website links from HTML / JSP / ERB and other platforms to Angular JS

Exploring the integration of AngularJS with a Spring MVC app (this detail is not crucial) and curious about the best Angular approach for passing a URL to the JS controller. I've noticed that most examples have URLs / paths hardcoded in the JS file, ...

What is the best technology to use for creating a web-based GUI Client?

My Python server is robust, with workflows, views, and object-oriented programming (ORM/OSV) capabilities. Communication between the server and client is based on the socket protocol, which can be implemented using XMLRPC service or Socket service. Now, I ...

Command "django-admin startproject" was initiated with the message "LOGGING_CONFIG setting was requested, however settings have

After successfully installing site-packages to a new location using the command pip install --target /opt/common/external/python_modules, I updated my PATH to include /opt/common/external/python_modules/django/bin/ and set my PYTHONPATH to reference the ne ...

Using a checkbox to sort through Google Maps markers

I want to create a filter for my google maps markers using checkboxes, inspired by this V3 example. Here's the HTML for the checkboxes: <form action="#"> Attractions: <input type="checkbox" id="attractionbox" onclick="boxclick(this,'a ...

Expo is having trouble locating the module "color-convert" - such a frustrating problem

Having an issue! I ran the command npm start in my terminal and received the following error: Starting project at /home/pc/Documents/Projects/Mobile/weather_app Developer tools running on http://localhost:19002 Cannot find module 'color-convert' ...

Displaying a cordova camera plugin captured photo within the IMG element

Seeking assistance with the Apache Cordova Camera API to display camera-retrieved images. I am able to capture the image, and the file URL looks like: file:///mnt/.....something.jpg However, I am encountering difficulty setting this image in an existing ...

Learn how to send multiple callback functions in a jQuery ajax request

I have a JS file with multiple ajax calls and I am looking to make one AJAX call that triggers multiple callback functions. Can anyone assist me in achieving this? Below is an example of the test code: $.ajax({ url : url, dataType : 'json', ...

Issue with closing in JavaScript code not functioning as expected

I recently created a toggle bar using HTML/CSS and I attempted to implement JavaScript code to close it. However, despite my efforts, the script doesn't seem to be functioning properly. Code: $(document).ready(function(){ $(".fa-times").click(functi ...

Executing an AJAX request in the onsubmit event of a form results in the form submission proceeding even when return false is

I am facing an issue with a form that I intend to use only for an AJAX call. The AJAX call is triggered on submit in order to utilize the auto-check feature for required fields. Despite returning false on submit, the form still submits. Surprisingly, when ...