Tips for maintaining the dimensions of Google chart columns while also implementing a scroll bar

I am working on a Google chart that will be generated through a database search to populate it. However, I have encountered an issue where if there are too many columns (representing different companies in my case), the size of the column bars keeps shrinking. You can see examples of this in the images below.

Image 1 with search limited to 10:

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

But when I add more companies without limiting my search results, I face this problem:

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

Is there a way to limit the size of the columns to that of the first image and create a scroll bar if it exceeds that size?

I have tried using the following CSS code but it did not work as expected:

#detailedCharts {
    overflow-x: scroll; 
    overflow-y: hidden;
    min-height: 500px;
    min-width: 100px;   
    width: 100%;
    height: 100%;
    margin-bottom: 5%;
}   

The code I am using for the chart is shown below:

 static drawChartGetTotalIssuesByCategoryAllCompanies(data) {
        let dataTable = new google.visualization.DataTable();

        dataTable.addColumn("string", "Company Name");
        dataTable.addColumn("number", "Issue Count");

        data.forEach(row => { dataTable.addRow([row.name, row.issueCount]) });
        let chart = new google.visualization.ColumnChart(document.getElementById("detailedCharts"));
        const options = {
            title: "Issues per Company for category",
            hAxis: {
                title: "Company Name"
            },
            vAxis: {
                title: "Issue Count"
            },
        };

        chart.draw(dataTable, options);
    }
}

The data I am passing in is an array of objects structured like this:

public int IssueCount { get; set; }
 public string Name { get; set; }

The HTML structure where the chart will be placed is as follows:

<div class="row">
            <div id="detailedCharts" class="col-sm-12">
                
            </div>

Do you have any suggestions on how I can achieve this layout while maintaining the appropriate size of the columns?

Answer №1

To address the issue with determining chart width based on CSS, here is a potential solution that involves adding flexible width functionality to your chart:

var numberOfElements = data.qg.length;

You can then calculate the new width by multiplying the number of elements with a desired value:

var newWidth = (numberOfElements * 100);

Add this calculated width to the options array under the width parameter:

var options = {
    width: newWidth
};

If you want to set a minimum threshold for generating width (e.g., only when there are more than 4 elements), you can use a conditional statement like this:

var newWidth =  (numberOfElements > 4) ? (numberOfElements * 100) : 0;

A similar approach can be used to define a minimum width requirement (e.g., generate width only if it exceeds 400):

var newGeneratedWidth =  (newWidth > 400) ? newWidth : 0;

Finally, update the width value with the new newGeneratedWidth:

width: newGeneratedWidth,

Check out an example implementation here: https://jsfiddle.net/e7de4e4h/

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

Update the image source with jQuery when hovering over it

Check out this code snippet: (view the fiddle here) <img class="changeable" src="http://placehold.it/100x120&text=anniversary"> <ul class="rollover_list"> <li><a href="#" rel="http://placehold.it/100x120&text=anniv ...

Tips for fixing flickering tables and bringing the scrollbar back to the top in your DataTable Forge viewer

Presently, I am working with a DataTable that consists of 100 rows and is being set up using lists. The lists dynamically change based on the selected name from a drop down. To achieve this, I use: $("#datatable").remove(); this.datatable = new Au ...

Pull data from a subdocument using Mongoose

Here is the content of my document: { password: '87654321', title: 'Organization A', members: [ { tier: 1, joinedDate: Sun May 12 2013 00:00:00 GMT+0200 (CEST), user: 543fc462ed385e5e77a98d56 }, { ti ...

Easily generate a hierarchical layout in HTML with this straightforward method

I'm currently working on implementing a hierarchical tree structure for a website. I need to organize a user's projects, tasks, and sub-tasks in a visually appealing manner using HTML elements. Any suggestions or creative ideas are welcome! ...

Arrange the placement of a box outside of the primary DIV while maintaining a connection to it

I've encountered a hurdle that's hindering my progress. I'm attempting to shift a small box containing various options (like report, like, dislike, etc.) out from the main DIV while keeping it securely attached from the outside. Let me illus ...

What could be causing my modal to malfunction?

I am facing an issue with implementing a modal on my website. When I click on the changelog, nothing happens as expected. Can anyone provide suggestions on how to resolve this problem? <button class="btn btn-primary" data-toggle="modal" data-target=". ...

Disable automatic playback once the page has loaded (Bootstrap carousel in Twitter)

I'm having an issue with my slider not autoplaying after the page loads. However, when I right-click, autoplay seems to turn on. What could be causing this problem? $('#myCarousel').on('slid', '', function() { var $t ...

HighCharts velocity gauge inquiry

I recently integrated a highcharts speedometer with PHP and MYSQL on my website. Everything seemed to be working smoothly until I added the JavaScript code for the speedometer, causing it not to display. There are no error messages, just a blank screen whe ...

What causes Angular projects to only display a single object when using an array?

I've been exploring the League of Legends API, specifically focusing on the champion json data it provides. Currently, I have developed a service using Angular: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders} f ...

Experiencing the error message "TypeError: cannot read properties of undefined" even though there are no undefined values when I use console.log

I've been working on a function that should retrieve the name of an item called collection_name within a user's account. In this specific case, the user is named hello. The API call returns an object so I'm converting it into an array using ...

Guide on passing a spread operator as an argument to a function's parameter

Utilizing the spread operator, I can extract the maximum value from two arrays by using Math.max(...firstArr, ...secondArr). It provides the correct value without manually adding a spread operator. To automate this process, I am attempting to create a func ...

"Enhance Your Website with Dynamic Google Map Marker Loading using Ajax

I am facing an issue with my Google map implementation. The map loads results on page load and I have an AJAX search form that updates the results in a separate div, but it doesn't update the map along with it. I need to figure out how to update the m ...

Unable to retrieve the data-id for each div element containing a data attribute

I am having trouble retrieving the ids from the data-id attribute of each div inside a specific container. Strangely, I am getting [7,7,7,7] even though there are only 3 divs with different data-ids? Below is my HTML structure: <div id="activated_bloc ...

Select the adjoining sibling in D3 and assign a class to it

I am faced with a challenge involving multiple group elements that are all siblings. My goal is to identify the one with the 'sliceActive' class, add the 'slice' class to it, and then move on to the next sibling and give it the 's ...

TypeScript incorporates a variety of @types versions for react

I made changes to my compilerOptions within the tsconfig.json file with the specified paths "paths": { "react": ["node_modules/@types/react"], "@types/react": ["node_modules/@types/react"] } However, I noticed that @types/react-router is using its o ...

What is the reason behind getComputedStyle having visibility set to visible?

What is the reason behind getComputedStyle always returning element visibility as visible even when no explicit visibility has been set? For instance: getComputedStyle($('#block1')[0],null).visibility; --- "visible" Meanwhile: $('#block1&a ...

Utilizing jQuery to verify each file upload individually within an array and pausing after each successful upload

Is it possible to utilize ajax for uploading images and assigning them names? The JavaScript function for uploading pictures is as follows: function sendFile(file) { $.ajax({ type: 'post', url: '@routes.CommonController.uploadhandl ...

Select2 Bootstrap - Preselecting Options

I am currently utilizing Bootstrap Multiselect but I am encountering some difficulties setting the default value for the multiselect as per the documentation provided. Inside a function, I have tried the following: $("#selector").multiselect("select", ["V ...

JavaScript Implementation for Validating Birthdates

I'm facing an issue with validating a Birthday date. I need to ensure that all fields are filled in, otherwise there should be an alert stating ("day must be chosen / month must be chosen"). How can I effectively run this validation script? Birt ...

Unable to assign headers once they have already been sent to the recipient - a Node.js error

Encountering an error message stating "Cannot set headers after they are sent to the client." I've researched and it seems like multiple callbacks may be causing this issue. However, I'm struggling to find a solution. Any assistance in resolving ...