Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Spacing between vertical bars with percentages set to 1 #3964

Closed
GlebEliseev opened this issue Feb 27, 2017 · 4 comments · Fixed by #5880
Closed

[BUG] Spacing between vertical bars with percentages set to 1 #3964

GlebEliseev opened this issue Feb 27, 2017 · 4 comments · Fixed by #5880

Comments

@GlebEliseev
Copy link

I am referencing #2216 since it is not working for me

The border width of the dataset is set to 0.
In options:

        scales: {
          xAxes: [{
            barPercentage: 1.0,
            categoryPercentage: 1.0,
            ...
          }]
        }

Here is the codepen where spaces can be seen.

chart

Is there a way to solve this?

Environment

  • Chart.js version: 2.5.0
  • Browser name and version: Google Chrome Version 56.0.2924.87
@etimberg
Copy link
Member

I'm guessing this a numerical/rounding error with the pixel calculations

@aresn
Copy link

aresn commented Mar 15, 2017

I did a little bit of digging and found out removing the Math.round inside DatasetScale.getPixelForValue function solves the problem. But it probably degrades the canvas performance because of sub-pixel rendering.

@sneilan
Copy link

sneilan commented May 12, 2017

Is there a way to override DatasetScale.getPixelForValue without modifying Chart.js?

@sneilan
Copy link

sneilan commented May 15, 2017

@aresn Is this how you modified the DatasetScale?

            var UserDefinedScaleDefaults = Chart.scaleService.getScaleDefaults("category");
            var UserDefinedScale = Chart.scaleService.getScaleConstructor("category").extend({
                // Used to get data value locations.  Value can either be an index or a numerical value
                getPixelForValue: function(value, index, datasetIndex, includeOffset) {
                    var me = this;
                    // 1 is added because we need the length but we have the indexes
                    var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);

                    if (value !== undefined && isNaN(index)) {
                        var labels = me.getLabels();
                        var idx = labels.indexOf(value);
                        index = idx !== -1 ? idx : index;
                    }

                    if (me.isHorizontal()) {
                        var valueWidth = me.width / offsetAmt;
                        var widthOffset = (valueWidth * (index - me.minIndex));

                        if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
                            widthOffset += (valueWidth / 2);
                        }

                        return me.left + widthOffset;
                    }
                    var valueHeight = me.height / offsetAmt;
                    var heightOffset = (valueHeight * (index - me.minIndex));

                    if (me.options.gridLines.offsetGridLines && includeOffset) {
                        heightOffset += (valueHeight / 2);
                    }

                    return me.top + heightOffset;
                },

            });
            Chart.scaleService.registerScaleType("user-defined", UserDefinedScale, UserDefinedScaleDefaults);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants