Changing the size of individual bars in a BarChartModel, without altering the overall appearance of the chart

Is there a way to adjust only the width of the bars in my chart without affecting the entire chart? Currently, everything is working fine but I specifically need to modify the bar width. Can someone help me with this? Below is the code I am currently using.

Java Code:

    private void createTaxaRetornoEventosBarModel(){

        this.taxaRetornoEventosBarModel = new BarChartModel();
        ChartData data = new ChartData();
        
        BarChartDataSet barDataSet = new BarChartDataSet();
        barDataSet.setLabel("My First Dataset");
        
        List<Number> values = new ArrayList<>();
        values.add(65);
        values.add(59);
        values.add(80);
        values.add(81);
        values.add(56);
        values.add(55);
        values.add(40);
        barDataSet.setData(values);
        
        List<String> bgColor = new ArrayList<>();
        bgColor.add("rgba(255, 99, 132, 0.2)");
        bgColor.add("rgba(255, 159, 64, 0.2)");
        bgColor.add("rgba(255, 205, 86, 0.2)");
        bgColor.add("rgba(75, 192, 192, 0.2)");
        bgColor.add("rgba(54, 162, 235, 0.2)");
        bgColor.add("rgba(153, 102, 255, 0.2)");
        bgColor.add("rgba(201, 203, 207, 0.2)");
        barDataSet.setBackgroundColor(bgColor);
        
        List<String> borderColor = new ArrayList<>();
        borderColor.add("rgb(255, 99, 132)");
        borderColor.add("rgb(255, 159, 64)");
        borderColor.add("rgb(255, 205, 86)");
        borderColor.add("rgb(75, 192, 192)");
        borderColor.add("rgb(54, 162, 235)");
        borderColor.add("rgb(153, 102, 255)");
        borderColor.add("rgb(201, 203, 207)");
        barDataSet.setBorderColor(borderColor);
        barDataSet.setBorderWidth(1);
        
        data.addChartDataSet(barDataSet);
        
        List<String> labels = new ArrayList<>();
        labels.add("January");
        labels.add("February");
        labels.add("March");
        labels.add("April");
        labels.add("May");
        labels.add("June");
        labels.add("July");
        data.setLabels(labels);

        this.taxaRetornoEventosBarModel.setData(data);
        
        BarChartOptions options = new BarChartOptions();
        CartesianScales cScales = new CartesianScales();
        CartesianLinearAxes linearAxes = new CartesianLinearAxes();
        CartesianLinearTicks ticks = new CartesianLinearTicks();
        ticks.setBeginAtZero(true);
        linearAxes.setTicks(ticks);
        cScales.addYAxesData(linearAxes);
        options.setScales(cScales);
        
        Title title = new Title();
        title.setDisplay(true);
        title.setText("Bar Chart");
        options.setTitle(title);

        Legend legend = new Legend();
        legend.setDisplay(false);
        legend.setPosition("top");
        LegendLabel legendLabels = new LegendLabel();
        legendLabels.setFontStyle("bold");
        legendLabels.setFontColor("#2980B9");
        legendLabels.setFontSize(24);
        legend.setLabels(legendLabels);
        options.setLegend(legend);

        this.taxaRetornoEventosBarModel.setOptions(options);
   }

XHTML and CSS, if you have any insights, please share:

<ui:composition xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:p="http://primefaces.org/ui">


    <div class="mt-5 d-flex justify-content-center" style="width: 100%; overflow-x: auto;">
        <div style="width: max-content;">
            <p:barChart model="#{MB.taxaRetornoEventosBarModel}" style="height: 400px; width: 1100px;"/>
        </div>
    </div>

</ui:composition>   

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

Answer №1

Try out the extender feature! This widget is similar to the Calendar module, as it is based on an external library called Chart.js

To get started easily, look at the bottom of this list:

Next, remove all other extender attributes (except for those you are already using) and include the "barThickness" attribute. Experiment with it using this helpful guide: https://www.chartjs.org/docs/latest/charts/bar.html#barthickness

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

Troubleshooting Issue with Absolute Positioning and Hover Effect on Material UI Button

I have a div containing a hidden button and an inner div filled with graphs and text. Occasionally, I need to blur the inner div and make the button float on top in the center of the blurred section, similar to the layout seen on subscription prompts found ...

Prevent styling on a fixed header in Jquery Mobile

Hello everyone, I am currently attempting to deactivate the theme/style on a fixed header within the following code snippet: <div id="home-header" data-role="header" data-id="mobile-header" role="banner" data-position="fixed" style="background-color: ...

Having an absolute element can lead to overflow causing a scroll

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .wrap { ...

Unusual Glitch in Bootstrap 3 Dropdown Menu

I am currently developing a website using Bootstrap 3. I am encountering an issue with the navbar dropdown. When I click on the link, it changes to show "expand child menu" and "collapse child menu". To clarify, here is the image I am referring to: Initi ...

What is the method for adjusting the width of a v-card based on its height?

I have a changing number of v-cards that are displayed based on their quantity. My goal is to maintain an aspect ratio of 16/9, but only adjust the width. To achieve this, I believe I need to make the width dependent on the height, although I am unsure ho ...

IE does not support 3D transform functionality

I am having an issue with 3D transformations on IE browser. It works fine on all other browsers except IE. If you have some time, please check the example first on a normal browser to see the transform and then try on IE. In the example, you need to click ...

Which is better: CSS gradients or background images?

Years ago, I came across many CSS codes that used background-image: url(xxx.png) to mimic a gradient background filter, as only (please correct me if I'm mistaken) IE's proprietary filter could achieve a CSS gradient. In today's world - giv ...

The Three.js IEWebGL Plugin

After developing a code that successfully rotates a cube with trackball using the three.js library and webgl, I encountered compatibility issues when trying to run it on Internet Explorer 10. Despite downloading IeWebgl to assist in making it run on IE10 ...

Loading CSS files from the Assets folder in Angular 2/4: Step-by-step guide

I have a question regarding my .angular-cli.json file configuration. Here is what I have defined: "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/assets/css/main.css", "styles.css" ], In my assets folder, I have CSS files loca ...

What is the method of aligning content to the left side in a slick slider?

My slider is set up to display three elements, but I'm having trouble aligning one or two elements to the left instead of centering them. jQuery(function () { jQuery('.slider-blog').slick({ arrows: false, dots: true, ...

The width of the Bootstrap row decreases with each subsequent row

I'm having trouble understanding this issue, as it seems like every time I try to align my rows in bootstrap, they keep getting smaller. Can anyone point out what mistake I might be making? ...

Hovering over an SVG icon will trigger an animation

I am trying to achieve an animated effect on an SVG line icon only when it is hovered over. I want the icon to remain static when not being hovered. While I have managed to animate the drawing effect and make it work somewhat on hover, I am facing an issue ...

Struggling with adjusting the image dimensions on my HTML and CSS page

<div class="profile"> <img src="image/JaeHeadShot.jpg" alt="Head Shot"/> <h1> Jae Hong </h1> </div> .profile{ border: 2px solid rgba(0,0,0,0.3); text-align:center; padding: 30px; } img.profile{ width:423; height ...

Tips for including vertical lines within text boxes to distinguish elements

I've been working on a simple form using CSS and HTML, but I'm struggling to add vertical lines to separate my text from the radio buttons. Right now, I'm just using '|' to divide them, but it's not the most visually appealing ...

The position of the HTML class shifts when the window is resized

I am in the process of creating a basic website layout that resembles this design. However, I am facing an issue where the webpage does not adapt well to different window sizes. Specifically, the elements with the classes .gameInfo and .playerList overlap ...

Contrasts in characteristics of CSS images versus SVG graphics

I'm curious if there are distinctions between CSS images and SVGs on your website. When referencing CSS images, I mean images constructed with div elements in HTML and then styled using CSS (such as this: https://codepen.io/andrewrock/pen/jOEZxrY). ...

The majority of the sliding banner is crafted using 90% HTML and CSS3, with just a touch

I devised a clever script to smoothly slide an image back and forth across the screen using CSS3. Unfortunately, I encountered a problem with CSS animations - they do not support changing the background-image directly. Attempting to overcome this limitatio ...

Explore a variety of themes for the antd design token

Is there a way to access the text color of both the default and dark themes using design tokens? I am looking for a method to seamlessly switch between the two color schemes based on specific conditions, without having to change the entire theme. For ins ...

A step-by-step guide on modifying the box-shadow color using jquery

I have developed some JavaScript code that adjusts the box-shadow of buttons to be a darker version of their background color. This allows users to dynamically change the button background colors. The current code successfully changes the box shadow based ...

Modify the color of the ion range-slider handle

When attempting to change the default color of ion range-slider (available at: https://github.com/IonDen/ion.rangeSlider) from red (default) to blue using the following code: .irs-slider.single { background: blue; } The slider shape changes from a th ...