How to make rounded corner bars in google charts


Mihir Bhatt

I have the following chart with square bars

enter image description here

I want it to make rounded bars using google charts like the image below

enter image description here

white hat

There is no standard configuration option to change the shape of the column

But you can directly modify the svg when the chart event is 'ready'fired

However, in any other case the chart will revert to its original shape

So need to modify, trigger an event at any time
-> 'ready', 'select', 'onmouseover','onmouseout'

To change the border radius of an rectelement , use the property rxandry

To make sure we have the correct rectelement,
custom is provided to the chart colors,
then the property is fillchecked to see if it exists incolors

rectAlso contains elements with fillattribute 'none',
which will be rectused to highlight the column'onmouseover'

and elements with attributes that mark the selected columnsrectstroke'#ffffff'

Also note that the svg seems to change the colorscase to lower case,
so lower case colorsis used in the array

See the working snippet below...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Month', '2015', '2016'],
      ['Jan', 10, 15],
      ['Feb', 12, 18],
      ['Mar', 14, 21],
      ['Apr', 16, 24]
    ]);

    var container = document.getElementById('chart_div');
    var chart = new google.visualization.ColumnChart(container);

    var colors = ['#cd6155', '#5499c7'];

    google.visualization.events.addListener(chart, 'ready', changeBorderRadius);
    google.visualization.events.addListener(chart, 'select', changeBorderRadius);
    google.visualization.events.addListener(chart, 'onmouseover', changeBorderRadius);
    google.visualization.events.addListener(chart, 'onmouseout', changeBorderRadius);

    function changeBorderRadius() {
      chartColumns = container.getElementsByTagName('rect');
      Array.prototype.forEach.call(chartColumns, function(column) {
        if ((colors.indexOf(column.getAttribute('fill')) > -1) ||
            (column.getAttribute('fill') === 'none') ||
            (column.getAttribute('stroke') === '#ffffff')) {
          column.setAttribute('rx', 20);
          column.setAttribute('ry', 20);
        }
      });
    }

    chart.draw(data, {
      colors: colors
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Related


How to make rounded corner bars in google charts

Mihir Bhatt I have the following chart with square bars I want it to make rounded bars using google charts like the image below white hat There is no standard configuration option to change the shape of the column But you can directly modify the svg when the c

How to make rounded corner bars in google charts

Mihir Bhatt I have the following chart with square bars I want it to make rounded bars using google charts like the image below white hat There is no standard configuration option to change the shape of the column But you can directly modify the svg when the c

How to make rounded corner bars in google charts

Mihir Bhatt I have the following chart with square bars I want it to make rounded bars using google charts like the image below white hat There is no standard configuration option to change the shape of the column But you can directly modify the svg when the c

How to make rounded corner bars in google charts

Mihir Bhatt I have the following chart with square bars I want it to make rounded bars using google charts like the image below white hat There is no standard configuration option to change the shape of the column But you can directly modify the svg when the c

How to make rounded corner bars in google charts

Mihir Bhatt I have the following chart with square bars I want it to make rounded bars using google charts like the image below white hat There is no standard configuration option to change the shape of the column But you can directly modify the svg when the c

How to make bars thicker in Kendo UI charts?

sony My graph contains calorie vs time data. Calories have a value every 15 minutes. I want to pull the bar closer. I am posting a sample of the data along with a link to jsFiddle. Also, is it possible to display the entire 24 hours on the graph and only show

How to make bars thicker in Kendo UI charts?

sony My graph contains calorie vs time data. Calories have a value every 15 minutes. I want to pull the bar closer. I am posting a sample of the data along with a link to jsFiddle. Also, is it possible to display the entire 24 hours on the graph and only show

rounded values in google charts

Jeremy Lin I'm using google charts, when using very accurate decimal numbers, GG charts tend to round it to 3 decimal numbers You can see it in the following example: google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCal

rounded values in google charts

Jeremy Lin I'm using google charts, when using very accurate decimal numbers, GG charts tend to round it to 3 decimal numbers You can see it in the following example: google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCal

Get rounded corners in Google Charts

Crazy Coder I'm using Google Charts to draw a column chart, but I need the rectangular bars to have rounded corners. Can someone help me? I have used google chart api to draw charts. Vadim Fedorov Try the Material Map https://developers.google.com/chart/intera

Google Charts Timeline - How to force bar labels inside bars

radiation proof I'm using Google's charting library to generate Gantt-like charts (using a timeline). barLabelOne problem I'm having is the automatic placement of libraries . It's very inconsistent when a long string should be truncated to place it in the labe

How to add error bars in Google Data Studio charts?

Plum I can see that there are STDDEV functions for calculated fields, but I can't find anywhere in the documentation that suggests adding or enabling error bars on the chart. Not supported? ! Bobby Rank I don't think it's possible at the moment, but it might b

Google Charts Timeline - How to force bar labels inside bars

radiation proof I'm using Google's charting library to generate Gantt-like charts (using a timeline). barLabelOne problem I'm having is the automatic placement of libraries . It's very inconsistent when a long string should be truncated to place it in the labe

Google Charts Timeline - How to force bar labels inside bars

radiation proof I'm using Google's charting library to generate Gantt-like charts (using a timeline). barLabelOne problem I'm having is the automatic placement of libraries . It's very inconsistent when a long string should be truncated to place it in the labe

Google Charts Timeline - How to force bar labels inside bars

radiation proof I'm using Google's charting library to generate Gantt-like charts (using a timeline). barLabelOne problem I'm having is the automatic placement of libraries . It's very inconsistent when a long string should be truncated to place it in the labe

Google Charts Timeline - How to force bar labels inside bars

radiation proof I'm using Google's charting library to generate Gantt-like charts (using a timeline). barLabelOne problem I'm having is the automatic placement of libraries . It's very inconsistent when a long string should be truncated to place it in the labe

How to add error bars in Google Data Studio charts?

Plum I can see that there are STDDEV functions for calculated fields, but I can't find anywhere in the documentation that suggests adding or enabling error bars on the chart. Not supported? ! Bobby Rank I don't think it's possible at the moment, but it might b

How to reorder bars in charts and legends

learning by mistake I'm struggling to reorder the bars in the plot and legend by data structure (SD, MB, FI, FO, NP). Here is my data; Data <- tibble::tribble( ~Year, ~SD, ~MB, ~FI, ~FO, ~NP, "2010", 41, 36.7, 10.2,

How to maximize bars in SVG charts

gcpreston I have an XML document with data that I want to draw in an SVG diagram using XSL. The chart is visible, but the individual bars do not fill the width of the chart and are almost visible on the y-axis. (as follows). How can I get the width of the bars

How to reorder bars in charts and legends

learning by mistake I'm struggling to reorder the bars in the plot and legend by data structure (SD, MB, FI, FO, NP). Here is my data; Data <- tibble::tribble( ~Year, ~SD, ~MB, ~FI, ~FO, ~NP, "2010", 41, 36.7, 10.2,

How to reorder bars in charts and legends

learning by mistake I'm struggling to reorder the bars in the plot and legend by data structure (SD, MB, FI, FO, NP). Here is my data; Data <- tibble::tribble( ~Year, ~SD, ~MB, ~FI, ~FO, ~NP, "2010", 41, 36.7, 10.2,

How to maximize bars in SVG charts

gcpreston I have an XML document with data that I want to draw in an SVG diagram using XSL. The chart is visible, but the individual bars do not fill the width of the chart and are almost visible on the y-axis. (as follows). How can I get the width of the bars