question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey, this is more of a question than an issue. I have a bar chart with distributeSeries: true, a lot of bars and rather wordy labels that overlap: labels-straight You can see the problem 😃 So, I have tried rotating the labels: labels-rotated Using this pattern I’d ideally want to force the labels to be one-line only and align perfectly with the bar. How can I achieve that? I’m also open for different ideas about positioning the labels.

Thank you very much, for this module and your help.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
klaemocommented, Jul 15, 2015

Solved it! Here’s the code

chart.on('draw', (ctx) => {
      if (ctx.type === 'label') {
        // adjust label position for rotation
        const dX = ctx.width / 2 + (100 - ctx.width)
        ctx.element.attr({ x: ctx.element.attr('x') - dX })
      }
})

and

.ct-chart-bar .ct-label.ct-horizontal.ct-end {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: rotate(-30deg);
  transform-origin: 100% 0;
  text-align: right;
  max-height: 1.5em;
  min-width: 100px;
  max-width: 100px;
}
4reactions
fdemmercommented, Jun 8, 2017

@eriknl1982 add axisX: {offset: ...} to add space for labels

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create Labels - W3Schools
How To Style Labels. Step 1) Add HTML: Example. <span class="label success"> ...
Read more >
CSS for Labels, Buttons and Form Interactions - HTML Goodies
This fourth part in a web development tutorial focuses on how to create and style form labels and buttons in CSS. Learn more....
Read more >
Tip: Styling the label element with CSS - Web Teacher
I made the labels display as block level elements, which were floated to the left. Then I assigned a width to the labels...
Read more >
HTML label style Attribute - Dofactory
The style attribute specifies the style, i.e. look and feel, of the <label> element. A style contains any number of CSS property/value pairs,...
Read more >
How to style labels with CSS? - Tutorialspoint
How to style labels with CSS? - To style labels with CSS, the code is as follows −Example Live Demo.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found