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

Specify the return type based on specific parameter value

I'm facing a situation where I have two definitions that are identical, but I need them to behave differently based on the value of the limit parameter. Specifically, I want the first definition to return Promise<Cursor<T>> when limit is g ...

"Encountering a net::ERR_UNKNOWN_URL_SCHEME error message when making an Ajax post request

I'm encountering an issue while attempting to make a post call using Ajax from my frontend to my Express server. The error message I'm getting is net::ERR_UNKNOWN_URL_SCHEME. Here's the code snippet for the Ajax request: function sendStep ...

Understanding how to use the 'this' variable in Vue components is essential for efficiently modifying DOM elements. Let's dive into a clarification on the usage of 'this'

Within my vue component, the structure is as follows: export default{ name: '', data: function () { return { var1 :{}, var2 : {}, ... } }, created: function () { this.methodName1() }, methods: { me ...

Display a delete icon when hovering over a Chip component from Material-ui

Recently, I've been exploring ways to implement the on-hover functionality for a chip. What I'm looking for is when I hover over a chip in an array of chips, it should display a delete icon. Below is the code snippet I've been working on: ...

When the text in a Material UI Textfield is updated using setState in React, the Hinttext may overlap with the newly set

How can I fix the issue of default hintText and floatingLabelText overlapping with text in a textfield when using setState to autofill the textfield upon clicking on an edit button? Here is an image showing the textfield overlap: Below is the code for th ...

Center the text vertically within a card using Vuetify styling

I am seeking a way to vertically align text within a card using Vuetify or traditional CSS in a Vue project. Here is my code: <template> <div> <v-container class="my-5"> <v-row justify="space-between"> <v- ...

Retrieve the Following Image from a Document through Ajax

I am working on an ASP.NET web application that displays photos from different sets. The image files are stored on the server and their locations are kept in a SQL database. I currently have this code to retrieve the first image: System.Drawing.Image img ...

creating a distinct angular service for every controller

Lately, I've been utilizing Angular services to store my commonly used codes that are required across different parts of my project. However, I have encountered an issue where variables in the service are shared between controllers. This means that if ...

Implementing an Angular theme in a project using Node.js, MySQL, and Express

I'm a beginner with node, angular, and express. I've managed to create a REST API using node+express+mysql, but now I need help integrating the blur-admin theme into my existing project. Despite getting the theme to run separately with gulp, I&ap ...

Obtaining the Div ID After Clicking on a Link

I'm attempting to fade out a box once the X in that box is clicked. I haven't been able to make it work even after searching on Google. I managed to get it working when clicking the div itself using $(this), but my goal is for it to work when the ...

When I tried to retrieve the value by using deferred.resolve(value) in my .then() method, it

I am currently utilizing Q.js to make an API call with two loops in my main function structured like this: for i..10 for i...5 var promise = getLoc(x,y); promise.then(function(value) { //value is undefined... ...

What sets apart jQuery's `click`, `bind`, `live`, `delegate`, `trigger`, and `on` functions, and how can they be utilized differently in coding

I have gone through the documentation for each function provided on the official jQuery website, but I couldn't find any comparison listings for the following functions: $().click(fn) $().bind('click',fn) $().live('click',fn) $().d ...

Having trouble with jQuery focus not functioning properly?

I've been attempting to implement a focus function on a specific input in order to display a div with the class name .search_by_name when focused. However, I'm encountering issues and would appreciate it if someone could review my code to identif ...

Oops! You forgot to include the necessary getStaticPaths function for dynamic SSG pages on '/blogs/[post]'

Whenever I attempt to execute npm run build, an error occurs. The following build error occurred: Error: getStaticPaths is required for dynamic SSG pages and is missing for '/blogs/[post]'. This is the code snippet causing the issue: function ...

What is the best way to search for a CSS selector that includes an attribute beginning with the symbol '@'?

Whenever I want to target an element with a click event, I usually use the following jQuery selector: $('div[@click="login()"]') <div @click="login()"> Login </div> However, when I tried this approach, it resulted ...

Removing data from firestore/storage does not follow the expected pathway

I have created an image gallery for users using Firebase Storage and React, allowing them to upload and delete images. However, I am facing an issue where the deletion process is taking longer than expected. Expected flow: User clicks on the trashcan ico ...

How can we modify this function to interpret multiple selections at once?

For the task of displaying multiple selections from a scrolling list to an alert, I have implemented the following function: var toppings = ""; function displaySelectedToppings() { var topList = document.getElementById('to ...

Using v-model with the Toast-UI editor in Vue.js adds a dynamic and

Is there a way to bind the input value while using toast-ui vue-editor since it doesn't support v-model? Here is my setup for toast-ui: import '@toast-ui/editor/dist/toastui-editor.css'; import { Editor } from '@toast-ui/vue-editor&apos ...

Unlocking the power of dynamic text using a single form

My comment reply system is experiencing an issue where the first reply works fine, but subsequent replies are unable to get the reply text value. How can I ensure that all replies work properly based on the Razor code provided below? <h4>Comments< ...

Utilizing jquery to showcase the information in a neat and organized table

Having an input text box and a button, I am looking to display dummy data in a table when any number is entered into the input field and the button is clicked. Here is what I have tried: My Approach $("button#submitid").click(function () { $(&quo ...