Rounded bars in ios Charts

后端 未结 3 1695
情歌与酒
情歌与酒 2021-02-05 23:04

I\'ve created a BarChart using BarChartView from ios-Charts but I can\'t figure out howto add rounded corners to bars.

This is the code that I\'m using:

3条回答
  •  北海茫月
    2021-02-05 23:49

    If you don't want to wait for this pull request to be merged in the original library, there's a working solution that I use myself in a couple of projects.

    This working example is based on all of the previous data I've collected all over the Internet. It works as of today but you have to do a few precautions before using it.

    To make it work, all you have to do is replace the whole BarChartRenderer.swift file with this one.

    First, have a backup copy of the original file. Then, make sure you replace the file every time you update your Charts CocoaPod, otherwise, the file will be overwritten.

    In the end, to control the corner radius of your chart, just change the barCornerRadius = CGFloat(5.0) to whatever you want to.

    Here's the final result I've got:

    After you've replaced the file, make sure to clean your Xcode's build folder and then recompile your project for changes to take effect immediately.

提交回复
热议问题