Discover the secret to loading multiple Google charts simultaneously, despite the limitation that Google charts typically only allow one package to load at a time

I currently have a pie chart displaying smoothly on my webpage, but now I am looking to add a treemap as well. The code snippet for the treemap includes the package {'packages':['treemap']}. It has been stated that only one call should be made to load function google.charts.load(). Even with the code structure in place, the treemap is not rendering properly.

$(document).ready(function () {
    $("#submit").click(function () {
        $("#pages").hide();

        var datefrom = $('#fromdatecalendar').val()
        var dateto = $('#todatecalendar').val()
        var model = $("#model_name").val().toString();
        var queryObject = "";
        var queryObjectLen = "";
        google.charts.load('current', { 'packages': ['corechart'] });
        google.charts.load('current', { 'packages': ['treemap'] });
        google.charts.setOnLoadCallback(drawChart);

        function drawChart() {
            $.ajax({
                url: "connect.jsp",
                type: "POST",
                data: { datetype: $('#fromdatecalendar').val(), datatocal: $('#todatecalendar').val(), model: $("#model_name").val().toString() },
                success: function (datas) {
                    var jsonData = JSON.parse(datas);
                    //loadData(jsondata);
                    var data = new google.visualization.DataTable();
                    var data2 = new google.visualization.DataTable();
                    // assumes "word" is a string and "count" is a number
                    data.addColumn('string', 'CATEGORY');
                    data.addColumn('number', 'COUNT_CAT');
                    data2.addColumn('string', 'CATEGORY');
                    data2.addColumn('string', 'SUB_CATEGORY');
                    data2.addColumn('string', 'SUB_CATEGORY_2');
                    data2.addColumn('string', 'SUB_CATEGORY_3');
                    data2.addColumn('string', 'SUB_CATEGORY_4');
                    data2.addColumn('string', 'SUB_CATEGORY_5');
                    data2.addColumn('number', 'COUNT_CAT');
                    for (var i = 0; i < jsonData.length; i++) {
                        data.addRow([jsonData[i].CATEGORY, jsonData[i].COUNT_CAT]);
                    }
                    for (var j = 0; i < jsonData.length; i++) {
                        data2.addRow([jsonData[j].CATEGORY, jsonData[j].SUB_CATEGORY, jsonData[j].SUB_CATEGORY_2, jsonData[j].SUB_CATEGORY_3, jsonData[j].SUB_CATEGORY_4, jsonData[j].SUB_CATEGORY_5, jsonData[j].COUNT_CAT]);
                    }
                    //alert(data);
                    var piechart_options = {
                        title: 'Category Count',
                        backgroundColor: '#f5f5f5',
                        pieSliceText: 'value',
                        is3D: true

                    };
                    var piechart = new google.visualization.PieChart(document.getElementById('chart_div'));
                    piechart.draw(data, piechart_options);

                    var barchart_options = {
                        title: 'Category',
                        backgroundColor: '#f5f5f5',
                        legend: 'none'
                    };
                    var barchart = new google.visualization.BarChart(document.getElementById('barchart_div'));
                    barchart.draw(data, barchart_options);

                    var tree = new google.visualization.TreeMap(document.getElementById('treechart_div'));

                    tree.draw(data2, {
                        minColor: '#f00',
                        midColor: '#ddd',
                        maxColor: '#0d0',
                        headerHeight: 15,
                        fontColor: 'black',
                        showScale: true
                    });
                    var showsubcat = document.getElementById("showsub");
                    showsubcat.onclick = function () {
                        var view = new google.visualization.DataView(data);
                        view.hideColumns([1]);
                        piechart.draw(view, piechart_options);
                    }


                },
                error: function (xhr, type) {
                    alert('server error occoured')
                }

            });

        }
    });
});

Answer №1

To load multiple packages at once, use the following method:

google.charts.load('current', {'packages': ['corechart', 'treemap']});

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

Steps for integrating a Facebook Messenger chatbot with a MongoDB database in order to submit requests and retrieve responses through conversations with the bot

I am currently working on integrating my Facebook Messenger chatbot with a MongoDB database. The chatbot I have created is a simple questionnaire chatbot that takes text inputs and displays buttons with options. When a user clicks on a button, it should ...

What is the best way to reference a component from another component in a React application?

I've been utilizing the react-notification-system library in my project, and here's a snippet of how I've incorporated it into my code. import React from 'react'; import Notification from 'react-notification-system'; cl ...

When using Ajax, Active Record in Codeigniter fails to update the database

Encountering an issue with codeigniter processing the script cleanly upon submission, but working fine when passing the data through ajax. The array output is visible using print_r, however, it fails to update the database after executing the activerecord ...

Receiving a PNG image in the response of a REST call from ServiceNow, the data appears to be garbled with junk characters

I encountered an interesting situation where I received a PNG image as a response from a REST call in ServiceNow. The response seems to be filled with junk characters, making it difficult to work with as shown below. My goal is to write a server script tha ...

JavaScript allows for the insertion of values into either a textbox or dropdown menu

Is there a way to restrict the client from inserting both of these fields: either selecting from a textbox (selected Column) or choosing a value from a dropdown menu (selected Column), but only one field is allowed in a gridview? <asp:GridView ID="gvMe ...

Using Regular Expressions in Firebase Functions to achieve a 'Clean Path' when utilizing app.use() in Express.js

Objective: I want Express to return /register when the browser URL is http://localhost:5000/register. This seemingly simple goal is proving to be a challenge with Express. Let's start by looking at my firebase.json: firebase.json: "hosting": { ...

It appears that the $http request is causing an endless $digest Loop

Looking to determine a user's status in my AngularJS app in order to display specific functionality content, here is the HTML code in my view: <span ng-show="authService.isSuperUser()">You are a Super User</span> To check if the user has ...

Ordering an array using Typescript within React's useEffect()

Currently, I am facing a TypeScript challenge with sorting an array of movie objects set in useEffect so that they are displayed alphabetically. While my ultimate goal is to implement various sorting functionalities based on different properties in the fut ...

Retrieving JSON information using JavaScript

I am encountering an issue with the "Ion.RangeSlider" library. I am attempting to dynamically load values via JSON, but I am unable to get the slider to accept the data from the "from" field. It is important that the value is not hardcoded since the user h ...

What is the best way to create a React text box that exclusively accepts numeric values or remains empty, and automatically displays the number keypad on mobile devices?

While there are numerous similar questions on StackOverflow, none of them fully address all of my requirements in a single solution. Any assistance would be greatly appreciated. The Issue at Hand Within my React application, I am in need of a text box tha ...

What is the process of sending an HTTP/HTTPS request from a Node.js server?

Currently diving into the world of Node.js, I am experimenting with using a Node.js Application on cPanel to generate a JSON response upon accessing its URL. Upon visiting the app's URL, it seems that the Node.js server is functioning correctly. Afte ...

Tips for adjusting border colors based on the current time

Trying to change the border color based on the opening hours. For example, green border from 10am to 9:29pm, yellow from 9:30pm to 9:44pm, and orange from 9:45pm until closing at 10pm. The issue is that the colors change at incorrect times beyond midnight. ...

Is there a way to access the element reference of a component directly within the template?

When I mouse over certain elements, I use the following code to set focus: <div #divTemplateVar (mouseover)="divTemplateVar.focus()"></div> However, this method does not work for components: <component #componentTemplateVar (mouseover)="c ...

Step-by-step guide on mocking an asynchronous function in nodejs with jest

Within this function, I need to mock the httpGet function so that instead of calling the actual function and returning its value, it will call a simulated function fetchStudents: async(req,classId) => { let response = await httpGet(req); return r ...

Tips for Properly Positioning Floating Pop-Up Messages Using CSS and jQuery

I was experimenting with adding a button that triggers a popup message to my website. I followed a coding tutorial using jQuery and CSS, which looks like this: Javascript : !function (v) { v.fn.floatingWhatsApp = function (e) {...} }(jQuery); CSS : .fl ...

"Switching from vertical to horizontal time line in @devexpress/dx-react-scheduler-material-ui: A step-by-step guide

Is there a way to switch the Time to a horizontal line using @devexpress/dx-react-scheduler-material-ui? <WeekView startDayHour={7} endDayHour={20} timeTableCellComponent={TimeTableCell} dayScaleCellComponent={DayScaleCell} /> Click ...

What's the best way to ensure a div's height and width are equal when implementing responsive design?

I am currently working on a responsive design and facing challenges in making div's height and width equal. Initially, I set the div's width as a percentage and height as auto, but this caused the divs to not display properly. To resolve this iss ...

Executing a function to erase the stored value in local storage during an Angular unit test

Looking to verify whether the localStorage gets cleared when I execute my function. Component ngOnInit() { // Logging out when reaching login screen for login purposes this.authService.logout(); } authService logout() { // Removing logged i ...

The React component designed to consistently render video frames onto a canvas is unfortunately incompatible with iOS devices

I'm facing an issue with my code snippet that is supposed to draw video frames on a canvas every 42 milliseconds. It's working perfectly on all platforms and browsers except for iOS. The video frames seem unable to be drawn on canvas in any brows ...

Can the second function be modified to incorporate the first one's syntax?

export const composeValidators = (...validators) => value => validators.reduce((error, validator) => error || validator(value), undefined); export const composeAccreditionValidators = (...validators) => value => validators.reduce((error, va ...