BarSeries and fixed width?

Thread is closed for posting
2 posts, 0 answers
  1. Regis
    Regis avatar
    1 posts
    Member since:
    Mar 2015

    Posted 24 Mar 2015 Link to this post


    How I can set a fixed width in BarSeries?

  2. Victor
    Victor avatar
    1358 posts

    Posted 25 Mar 2015 Link to this post

    Hello Regis,

    Thanks for writing.
    Currently the only way to do this is to override the rendering of the bars. For example:
    public class CustomBarRenderer extends BarPointRenderer {
        private HashMap<DataPoint, PaletteEntry> pointColors = new HashMap<DataPoint, PaletteEntry>();
        public CustomBarRenderer(BarSeries series) {
        public HashMap<DataPoint, PaletteEntry> pointColors() {
            return this.pointColors;
        protected void renderPointCore(Canvas canvas, DataPoint point) {
            BarSeries series = this.getSeries();
            float roundBarsRadius = series.getRoundBarsRadius();
            RadRect layoutSlot = point.getLayoutSlot();
            if(layoutSlot.getHeight() == 0 || layoutSlot.getWidth() == 0) {
            RectF pointRect = Util.convertToRectF(layoutSlot);
            Paint fillPaint;
            Paint strokePaint;
            if(series.isPaletteApplied() && this.pointColors.containsKey(point)) {
                PaletteEntry entry = this.pointColors.get(point);
                fillPaint = new Paint();
                strokePaint = new Paint();
            } else {
                strokePaint = series.getFillPaint();
                fillPaint = series.getStrokePaint();
            float strokeWidth = this.getSeries().getStrokeWidth();
            strokeWidth /= 2.0f;
            pointRect.left += strokeWidth;
            pointRect.right -= strokeWidth;
   += strokeWidth;
            pointRect.bottom -= strokeWidth;
            if (series.getAreBarsRounded()) {
                canvas.drawRoundRect(pointRect, roundBarsRadius, roundBarsRadius, fillPaint);
                canvas.drawRoundRect(pointRect, roundBarsRadius, roundBarsRadius, strokePaint);
            } else {
                canvas.drawRect(pointRect, fillPaint);
                canvas.drawRect(pointRect, strokePaint);
        private void clampPointRect(RectF rect) {
            // adjust point rect here

    Just fill in the clampPointRect() method to make the bars as wide as you need.

    Then you have to call barSeries.setDataPointRenderer(new CustomBarRenderer(barSeries));
    Keep in mind that there appears to be an issue that causes the chart palette to not be applied to the custom renderer so you will have to adjust the bar colors as well.

    Please write again if you have more questions.


    See What's Next in App Development. Register for TelerikNEXT.

Back to Top