What could be causing my Dojo Pie chart to vanish when I trigger the updateSeries function following an Ajax request?

I'm currently working on updating a dojo Pie chart using the updateSeries method. The method is called after an ajax request to retrieve an updated JavaScript array data.

Below is the JavaScript code:

var eventByReasonsData = .... //data is populated during JSP page compilation

var theme = dojox.charting.themes.Julie;

var eventReasonsChart = null;


function makeEventsByReason() {

    var dc = dojox.charting;
    eventReasonsChart = new dc.Chart2D("eventsByReasonChart");
    eventReasonsChart.setTheme(theme).addPlot("default", {
        type: "Pie",
        font: "normal normal 8pt Tahoma",
        fontColor: "black",
        labelOffset: -20,
        radius: 100

    }).addSeries("eventSeries", eventByReasonsData);

    var anim_a = new dc.action2d.MoveSlice(eventReasonsChart, "default");

    var anim_b = new dc.action2d.Highlight(eventReasonsChart, "default");

    var anim_c = new dc.action2d.Tooltip(eventReasonsChart, "default");

    eventReasonsChart.render();


}

Here is the HTML code:

<div id="eventsByReasonChart" ></div>

And here is the JavaScript code for the AJAX call:

new Ajax.Request( url, {
        method: 'post',
        parameters: params,
        onComplete: function(response) {


            if( response.responseText != "empty" )
            {
                var chart = eventReasonsChart;

                eventByReasonsData = response.responseText;

                chart.updateSeries( "eventSeries", eventByReasonsData );

                chart.render();                                                 
            }

        }
    });

Lastly, here is the format of the data sent to the chart:

[{ y:48 },{ y:1 },{ y:1 },{ y:14 },{ y:7 },{ y:3 },{ y:8 }]

Initially, the chart is drawn without any issues. However, after the AJAX call, the chart disappears after the update call without any visible errors on the console.

Any ideas on what might be causing this issue?

Answer №1

It seems like the variable eventByReasonsData may be a string, while the function updateSeries() is looking for an array. To fix this, you can utilize the dojo.fromJson() method to convert the string into an array:

chart.updateSeries( "eventSeries", dojo.fromJson(eventByReasonsData) );

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

Creating PNG images in a scripting language for web applications

Imagine giving your website user the ability to specify a radius size, let's say 5px, and in return receiving a PNG file with a circle of that radius. This question can be divided into two sections: In what language and using which technologies can ...

How to retrieve response cookies using RxJS Ajax

When using RxJS to make an Ajax call request, I am able to set the headers of the request. However, I am wondering how I can retrieve the Cookie from the RxJS Ajax Response? import { ajax } from 'rxjs/ajax'; ajax({ url: "some url", body: ...

Magical Stylist - Eradicate Indicators while Preserving Labeling

Recently, I've been experimenting with the Google styling wizard in an effort to remove markers while retaining labels for businesses. My objective is to eliminate the marker icons but still display the text labels such as "Jimmy Johns," "Boone Saloon ...

Sliding the container with a width adjustment and left margin fails to display all images

In the provided HTML code below, there is a functionality to move images horizontally by clicking on buttons: $(document).ready(function() { calculate_width(); $('#moveleft').click(function() { var loga = $('#marki #loga'); ...

Personalize the Jquery datatables GET request parameters for the server by tailoring them to your preferences

I'm using Jquery datatables and would like to customize the GET request it sends to the server when loading a page, instead of the default GET request. Below is the JavaScript section where the request is sent on load: $(document).ready(function() { ...

Creating operations in Angular using the Model View Controller (MVC)

What is the procedure for performing an Add operation in MVC using Angular? var addProductModule = angular.module("addProductModule", []); addProductModule.factory("addProductService", ['$http', function ($http) { return { function savePro ...

"Understanding How to Utilize the Grpc Stream Variable for Extended Processes in Node.js

Utilizing Node.js for connecting to a server through gRPC in order to execute a lengthy task. The server sends a one-way stream to the client (Node.js app) while the task is ongoing. I am looking to add a Stop button and have been advised that closing the ...

Oops! There was an error: Uncaught promise rejection: TypeError - Unable to access 'subscribe' property of null object (Ionic Angular)

I encountered an issue in my angular ionic project. When I log in, the first page displays the error "ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subscribe' of null." However, upon reloading the page, the error disappears ...

jQuery Autocomplete API Issue: Undefined

I've been attempting to implement a basic text box using the jQuery API from DevBridge. I followed instructions in this video tutorial to create my code. However, despite properly declaring scripts before the JS code and ensuring proper mappings, I&a ...

What is the best way to retrieve the name of a dynamic form in a Controller

How can I retrieve the dynamic form name in my controller? See below for the code snippet: HTML <form name="{{myForm}}" novalidate> <input type="text" ng-model="username" name="username" required/> <span ng-show="(submit & ...

What is the best way to synchronize the scale of images with the tempo of a song?

I just started learning CSS, JS, and HTML and I have a question about scaling an image based on a song. Despite searching through YouTube and various forums, I still haven't found a solution. Any help would be greatly appreciated :) Here is the HTML ...

Vue.js component mismatch in the layout

Attempting to set up a Vue application with vuetify while incorporating layouts. As a newcomer to Vue, I may have made some beginner errors. Here is the structure of my app: main.js // The Vue build version to load with the `import` command // (runtime- ...

Can modifications be made to a page's source content variable using Ajax?

Can modifications be made to the source content of a page through Ajax loaded by a jsp include in the main jsp? If not, is it possible to refresh only that portion of the page (the jsp that loads some of the content) and have a portion of the content in t ...

The data provided was deemed incorrect. Modifying the function to include file uploads in Laravel 8 and Vue 2

I've been attempting to create an update function that includes file upload capability. Here is what I have experimented with so far: <b-form @submit.prevent="update" enctype="multipart/form-data"> . . . . <b-form-f ...

Troubleshooting a scope problem with ng-include while maintaining the original template

I have a select box within my template that has the following structure: <form name="myForm" class="fixed-select"> <select name="repeatSelect" id="repeatSelect" ng-model="selectedItem"> <option ng-repeat="program in pro ...

Issue with Bootstrap 3 dropdown not receiving updates

My goal is to dynamically populate a bootstrap 3 dropdown menu from a MySQL database. Everything works perfectly the first time I load the data. However, when I add more rows to the database, they do not automatically show up in the dropdown. Only after ...

Resolved the time zone problem that was affecting the retrieval of data from the AWS Redshift database in Next

Currently utilizing Next.js for fetching data from AWS Redshift. When running a query from DataGrip, the results display as follows: orderMonth | repeatC | newC 2024-02-01 | 81 | 122 2024-01-01 | 3189 | 4097 However, upon retrieving the same query ...

I'm facing a challenge with discord.js where I can't seem to get multiple prefixes to work. Do you have any suggestions on how I can modify it to

As the title suggests, I've been experimenting with different versions of the code below. The current version can recognize firstPrefix but not secondPrefix. I simply want my discord bot to be able to identify both prefixes and split the Args accordin ...

Check for the presence of an Outlook add-in within a web application

I'm having trouble determining whether my hosted web application is being accessed through a browser or from within the Outlook 2013/2016 client. I have developed a web application that offers different functionalities depending on whether it is acce ...

Created a notification for when the user clicks the back button, but now looking to remove it upon form submission

My survey is lengthy and I don't want users to accidentally lose their data by clicking the back button. Currently, I have an alert that warns them about potential data loss, but the alert also pops up when they submit the form. Is there a way to disa ...