Skip to content

How to rotate x labels in BarChart? #138

Open

Description

@daniele22

Is there a way to rotate the labels in a bar chart and set them e.g. in vertical position because if the labels are too long they overlap each other.

dbscan_DistanceToNearestNeighbor

I tried the following code, the labels rotate but the resulting plot is not good

BarChart.custom(data.map(Bar.apply), spacing = Some(20), barRenderer = Some(labeledByColor))
      .discreteAxis(position = Position.Bottom, labels = labels, values = data , tickRenderer = 
             Some(TickRenderer.axisTickRenderer(Position.Bottom, rotateText = 45)))
      .hline(0)
      .render()

dbscan_DistanceToNearestNeighbor

Activity

  1. berlinguyinca commented on Aug 9, 2023

    @berlinguyinca

    Did you ever solve this issue? I'm facing the same issues here

  2. berlinguyinca commented on Aug 14, 2023

    @berlinguyinca

    nevermind this did the trick

    
          val dataPoints = Seq(("test",1.0))
    
          def formater(x: Double): String = {
            dataPoints(x.toInt)._1
          }
    
          val plot = BarChart
            .clustered(dataPoints.map(x => Seq(x._2))
            )
    
            .xAxis(tickRenderer =
              Some(TickRenderer.axisTickRenderer(Position.Bottom, rotateText = 90)), labelFormatter = Some(formater), tickCount = Some(foundTargets))
            .ybounds(-1, 1)
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions