bytebeats / compose-charts

Simple Jetpack Compose Charts for multi-platform. Including Android, Web, Desktop.
MIT License
158 stars 16 forks source link

Custom Labels for numeric values on Y-Axis #28

Closed MarcelJurtz closed 2 years ago

MarcelJurtz commented 2 years ago

I would like to replace the labels on the y-axis in a bar diagram while keeping the original structure. In my use case, I display an amount of time per day of week, which is currently displayed in minutes, but I'd like to change the format to something like 2:30 instead of 150. Is there an option for that?

bytebeats commented 2 years ago

@MarcelJurtz Yes. There are APIs for formatting labels of x or y axises.

In your case, you may do like this:

        BarChart(
            barChartData = barChartDataModel.barChartData,
            labelDrawer = barChartDataModel.labelDrawer,
            yAxisDrawer = SimpleYAxisDrawer(labelValueFormatter = { value ->
                "your regex here".format(
                    value
                )
            })
        )
MarcelJurtz commented 2 years ago

Thank you! I'll give that a try later.

Edit: Worked out for me. Thanks!