question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Possible Bug] Bar Chart doesn't display right border

See original GitHub issue

I’m building a bunch of charts for my project and I just noticed an oddity in vertical bar graphs I am not seeing in line charts. The bar charts don’t display the right border. I have tried placing ‘drawBorder: true’ in both Axes but nothing has changed. Is this a bug or am I missing something in the documentation?

Below is my config for the graph

    var config = {
        type: 'bar',
        data: {
            labels: xdata,
            datasets: [{
                label: 'Fake',
                data: supply,
                borderColor: primary,
                backgroundColor: primary
            }]
        },
        options:
        {
            title: {
                display: true,
                text: "Fake",
                fontSize: 22,
                fontStyle: 'bold',
                fontColor: '#000000'
            },
            legend: {
                display: false,
                position: 'right'
            },
            layout: {
                padding: { left: 10, right: 80, bottom: 10, top: 10 }
            },
            scales: {
                xAxes: [{
                    gridLines: {
                        drawBorder: true
                    },
                    scaleLabel: {
                        display: true,
                        labelString: 'Fake',
                        fontStyle: 'bold',
                        fontSize: 16
                    }
                }],
                yAxes: [{
                    ticks: {
                        min: 0
                    },
                    gridLines: {
                        drawBorder: true
                    },
                    scaleLabel: {
                        display: true,
                        labelString: 'Fake',
                        fontStyle: 'bold',
                        fontSize: 16
                    }
                }]

            }
        }
    };

image

Notice the line chart with no settings altered for the borders works fine

image

In fact the bar chart in the documentation has the same issue. image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ChaseLewiscommented, Jan 19, 2017

I got ya, I haven’t messed much with multiple same dimension Axes charts so other than a different border property I’m not sure how people with that criteria would like to handle it. A separate border property that only draws if defined and it defaults to undefined makes the most sense to me, off the top of my head though I haven’t looked much into it.

Writing a modification for that would be simple enough if there was an agreed upon data setup (border I’d expect in the options.chartArea.border. I’d personally vote for separate border property that defaults to the same colors as the Axes. I’ll do a pull request and see what people think, as if it modified project code you’d need more feature options like rounding, strokeWidth, joins, etc. For now I’m just using the primary xAxes color so the left & right match with the plugin below to fix the issue.

Chart.plugins.register({
    beforeDraw: function (chart, easing) {
        var ctx = chart.chart.ctx;

        if (chart.config.type === 'bar')
        {
            //Save the rendering context state
            ctx.save();

            ctx.strokeStyle = chart.config.options.scales.xAxes[0].gridLines.color || Chart.defaults.bar.scales.xAxes[0].gridLines.color || "rgba(220,220,220,0.8)";
            ctx.lineWidth = chart.config.options.scales.xAxes[0].gridLines.lineWidth || Chart.defaults.bar.scales.xAxes[0].gridLines.lineWidth || 2;

            ctx.beginPath();
            ctx.moveTo(chart.chartArea.right, chart.chartArea.top);
            ctx.lineTo(chart.chartArea.right, chart.chartArea.bottom);
            ctx.stroke();

            //Restore the rendering context state
            ctx.restore();
        }
    }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Highcharts stacking bar chart border not displaying on right side
Please note: Setting the borderWidth property to higher than 1 works in displaying, but the rightmost border is much thinner than the others....
Read more >
Format the bar chart of a Gantt Chart view - Microsoft Support
In the Name field, click the type of Gantt bar (such as Task or Progress) that you want to format, and then click...
Read more >
Bar Chart | Chart.js
A bar chart provides a way of showing data values represented as vertical bars. It is sometimes used to show trend data, and...
Read more >
Bar Charts | Google Developers
Like all Google charts, bar charts display tooltips when the user hovers over the data. For a vertical version of this chart, see...
Read more >
Floating Bars in Excel Charts - Peltier Tech
In a waterfall chart, floating bars (usually vertical) show how contributing ... and use Plus Error Bars for our floating bars (right).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found