Creating a pie chart with a legend in the realm of the dojo

Apologies for any language errors.

I am looking to develop a web application where users can fill out a form and submit it to the server. The server will then respond with the requested data in JSON format. Using this data, I want to create a diagram and a legend using Dojo. The generated graph and legend should resemble this image:

1 Question: How can I display custom text in the legend instead of numbers (47, 14, 11, etc.) based on the JSON object?

2 Question: I am currently using the Claro theme in Dojo which has only 5 colors that repeat. How can I assign unique colors to each sector of a circle in the chart?

3 Question: When a new query is made by the user, I need to clear the old chart and legend and display the new ones. While this works for the chart, the legend remains hidden and does not update. What could be causing this issue?

The client-side code appears as follows:

<script>
require(["dojo/dom", 
         "dojo/on", 
     "dojo/request", 
     "dojo/dom-form",
     "statsDiagramme/kreisDiagramm",
     "statsDiagramme/stabDiagramm",
     "dojo/json", 
     "dojox/json/query", 
     "dijit/Dialog", 
     "dijit/form/Button",
      "dojo/domReady!"],

function(dom, on, request, domForm, kreisdiagramm, stabdiagramm, json){

     var form = dom.byId('sqlOptForm');      
     on(form, "submit", function(evt){                      
         evt.stopPropagation();         
         evt.preventDefault();      

         request.post("ServletStatsSQLOPT", {       

    data: domForm.toObject("sqlOptForm"),   
    handleAs: "json"

     }).then(function(response){

    var error = dojox.json.query("fehlermeldung", response);

    if(error === ""){   
                                dojo.html._emptyNode("statsKreisDiagramm");
                                dojo.html._emptyNode("statsStabDiagramm");
                                dojo.html._emptyNode("legende");

                                stabdiagramm.setStabDiagramm(response); 
                                kreisdiagramm.setKreisDiagramm(response);
                                dom.byId("statsKreisDiagramm").style.visibility = 'visible';
                                dom.byId("statsStabDiagramm").style.visibility = 'hidden';
                                dom.byId("statsMenuButton").style.visibility = 'visible';
                                dom.byId("legende").style.visibility = 'visible';                   

    }
    else {                  
        // ERROR 

    }

    }, function(error) {    
        // ERROR 

        });
        });
    }
    );
</script>

The chart creation script is defined as:

define([
"dojox/charting/Chart",
"dojox/charting/themes/Claro",
"dojox/charting/plot2d/Pie",
"dojox/charting/action2d/Tooltip",
"dojox/charting/action2d/MoveSlice",
"dojox/charting/widget/Legend",
"dojox/charting/plot2d/Markers",
"dojox/charting/widget/Legend",
"dojox/charting/axis2d/Default",

"dojo/domReady!"
], 
function(Chart, theme, PiePlot, Tooltip, MoveSlice, Legend){

    return{
        setKreisDiagramm: function(response) {

            var data = new Array(response.summeArray.length);          
            // response => JSON object
            for(var i=0; i < response.summeArray.length; i++) {
                data[i] = { x: 1, y: response.summeArray[i].summe };   
            }

            var pieChart = new Chart("statsKreisDiagramm");        

            pieChart.setTheme(theme);          


            pieChart.addPlot("default", {
                type: PiePlot,                  
                radius: 180,
                fontColor: "black",
                labelOffset: 30,                
                markers: true
            });

            pieChart.addSeries("Summary", data);      

            var tooltip = new Tooltip(pieChart, "default");        

            var moveSliceAction = new MoveSlice(pieChart,"default");       

            pieChart.render();

            var chartLegend = new Legend({ chart: pieChart, horizontal: false },   "legende");


        }
    };
}
);

Any assistance would be greatly appreciated. Thank you!

Answer №1

To address question 2:

There are options to either create your own custom theme or use a preexisting dojo theme for your pie chart.

If you're looking for examples and explanations, check out this link: specifically in the Point Chart Themes section

For more information on available themes, visit the API documentation here:

You can also preview these themes by visiting:

I hope this information proves helpful.

Best regards, Miriam

Answer №2

To eliminate a myth, it must be dismantled completely. Here is the solution to question 3:

var myth = dijit.byId("myth");
if (myth) {
  myth.destroyRecursive(true);
}

var legend = new dojox.charting.widget.Legend({ chart: pieChart, horizontal: false }, "myth"); 

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

Alerts for drop down menu validation with multiple buttons

My goal is to design a multi-step form that collects user information. This form consists of 5 stages: Step 1: User details (Name, email, phone, age, gender) Step 2: Yes or No question Step 3: Yes or No question Step 4: Yes or No question Step 5: Yes o ...

Negatives of utilizing two different UI libraries within a single react project?

I have been contemplating a decision that may be considered unconventional from a technical standpoint. Despite my search efforts, I have not come across any explanation regarding the potential drawbacks of this decision. Imagine creating a React website ...

What is the best way to update a deeply nested array of objects?

I have an array of objects with nested data that includes product, task, instrument details, and assets. I am attempting to locate a specific instrument by supplier ID and modify its asset values based on a given number. const data = [ { // Data for ...

Discover the exclusive Error 404 dynamic routes available only in the production version of NEXT13! Don

Hey everyone, I'm encountering an issue with NEXT's dynamic routing (Next 13). My folder structure looks like this: - user/ -- [id]/ --- page.js It works fine in dev mode but not in production. What am I trying to do? I've created a "page ...

Issues with JSON parsing functionality in Swift

Struggling with developing an IOS app in Xcode 6 using swift, I am finding myself frustrated and confused due to my lack of experience in the language. Attempting to view JSON results from an API call to LastFM using NSLog("%@", allResults), I encountered ...

Organize your blog content by utilizing post IDs as the designated id attribute

What is the best way to format blog posts and comments in HTML so that I can easily manipulate them later using jQuery/Javascript for tasks like updating, deleting, or making Ajax calls? I am considering using the IDs (primary keys in the database) of the ...

Easiest method to globally disable form autocompletion in an application without manually setting autocomplete off for every individual form

Is there a quick way to disable autocomplete in all forms within the application without individually adding "autocomplete=off" to each form? ...

Issue Arising from Printing a Custom Instruction in a Schema Generated Document

When dynamically adding a directive, the directive is correctly generated in the output schema. However, it seems to be missing when applied to specific fields. Here is how the directive was created: const limitDirective = new graphql.GraphQLDirective({ na ...

Using Angular's $http service to send a file to a web API endpoint from a post function

I'm facing an issue with uploading a javascript file or transmitting a javascript file to a post function. On the client side, I am using angularjs $http service to send the data as follows: $http({ method: "POST", ...

Error encountered when attempting to retrieve data from an API route using s3, resulting in an uncaught promise with the message "SyntaxError: Unexpected token < in JSON at position 0

I'm attempting to retrieve a JSON file from an S3 bucket. Here is the API route I'm using to fetch the json file: const {GetObjectCommand, S3Client} = require("@aws-sdk/client-s3"); const client = new S3Client() // Add opts to S3 if nee ...

What is the explanation for the outcome "-9 >> 2 = -3"?

What is the reason behind 9 >> 2 = 2 compared to -9 >> 2 = -3 ? Wouldn't it make more sense for it to be -2 instead? ...

Populate an HTML table with the days of the month and corresponding dates retrieved from a PostgreSQL database using JavaScript

I'm struggling to figure out how to use generate_series to populate an HTML table where the 'key' of <tr> corresponds to the days of the selected month and year using an <input type='month'>. So far, with the help I re ...

jQuery - restrict input field based on the value of a different selected field

Could anyone recommend a jQuery plugin that can achieve the following functionality? For example: <label><input type="checkbox" depends_on="foo=5" name="boo" ... /> Check </label> <select name="foo" ... > <option value="5" se ...

Material-ui does not adjust Typography color based on the theme selected

Exploring material-ui, I have implemented two themes: const darkTheme = createMuiTheme({ palette: { type: "dark" } }); const lightTheme = createMuiTheme({ palette: { type: "light" } }); However, when utilizing the Typography component, t ...

The propagation of onClick events in elements that overlap

Having two divs absolutely positioned overlapping, each containing an onClick handler. The issue is that only the top element's onClick handler fires when clicked. React 17 is being used. Here is some sample code: <div style={{ position: "abs ...

What is the best approach to link an HTML document to a MySQL Workbench server utilizing JavaScript, Ajax, and PHP?

On my HTML page, users can enter the name of a movie and if it is found in the database, the name will be displayed. I am attempting to establish a connection to the MySQL Workbench Server using JavaScript, Ajax, and PHP. This is what I have implemented s ...

Efficient method invocation for objects within an array using functional programming techniques

Is there a way to execute a method that doesn't require arguments and doesn't return anything on each object within an array of objects that are all the same type? I've been trying to find a solution without resorting to using a traditional ...

Sharing data between two components on the same level in Vue.js

I have a situation where I need to transfer data from one component1 to another component2. I am not utilizing vuex or router for this task. The component tree looks like this: -Parent --Component1 --Component2 In the first component1, I am sending an ...

Is there a way to alter visibility once a radio button has been selected?

I have a shape resembling a cube with 4 faces, all of which are currently visible. However, I would like to hide the other 3 faces when one face is showing. For example: I attempted setting the opacity of the other cube sides to 0 when the first radio but ...

How can you access the query in Next.js API when req.query is initially set to undefined?

Is there a way to compare the value of req.query with the cookies on the site, even when req.query is undefined upon initial load? How can this be addressed? export default async function handler(req, res) { const { method } = req; const userId = req ...