Modify the c3 axis labels using CSS

I've been using the c3 package in R, which serves as a wrapper for the C3 javascript charting library created by Masayuki Tanaka.

One issue I encountered is that my c3 chart was cutting off the last date on the x-axis. After inspecting it in Chrome Inspector, I manually adjusted the text-anchor: middle to text-anchor: end

This workaround seemed to resolve the problem:

However, I'm unsure how to achieve this through CSS styling alone.

Below is a snippet of my R script along with the relevant CSS code. While I believe the issue lies more within the CSS aspect, here are the details:

R Script

library(shiny)
library(c3)

data <- data.frame(a = abs(rnorm(20) * 10),
                   b = abs(rnorm(20) * 10),
                   date = seq(as.Date("2014-01-01"), by = "month", length.out = 20))

ui <- fluidPage(
  
  includeCSS("c3.css"),
  
  c3Output("chart",  height = "100%")
)

server <- function(input, output, session) {
  output$chart <- renderC3({
    data %>
      c3(x = 'date') %>
      tickAxis('x', count = 5, format = '%Y-%m-%d') 
  })
}

shinyApp(ui, server)

CSS Styling

.c3-line {
  stroke-width: 4px !important; 
}

.c3-axis-x-label {
    text-anchor: end; 
}

Answer â„–1

No code has been provided here, but the following snippet may be helpful:

.c3-axis-x g.tick:nth-last-child(3) text {
  transform:translateX(-5%);
}

Ensure you target the text correctly and adjust the value as needed.

Update: The correct selector is not :last-child - revised based on actual code. Make sure to target your selector accurately and apply the transform property.

Update 2: Turns out it was the group .c3-axis-x that contains the tick texts. Code has been updated once again.

Answer â„–2

Something that comes to mind right away:

Your current CSS is only targeting the 'date' element. The other 'text' element does not have a class, so the CSS for '.c3-axis-x-label' will only affect the first text element.

Try adding the 'c3-axis-x-label' class to your other 'text' element as well.

Another point to consider:

The 'text' tag you want to modify has its styles written within the tag https://i.stack.imgur.com/2nwww.png

When styles are set this way, they will always take precedence over applied CSS.

One solution I can suggest is to use !important in your CSS to override the inline style. I generally advise against using !important, but if it's too challenging to directly modify the CSS, this could be an option.

If you can assign a class to the other text element, try applying styles to 'text' in your CSS:

g > text {
   text-anchor: end; 
}

Let me know if any of these suggestions were helpful. If not, providing some code would be beneficial in assisting you further.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enumerate contained in a column of a data table

Currently, I have initialized a data.frame with one column containing set values: df <- data.frame(N=seq(10, 100, by=10)) Now, my goal is to add a second column that holds a list (or c()) of integers. The desired output when calling df should look lik ...

"Creating Rounded Corners in HTML: A Step-by-Step Guide

Is there a way to round the corners of this image? Below is an excerpt from my body... <body> <h1 style="float:left; width:37%;"><font color="#99CC00"><font face="Verdana">MrEpicGaming4U</font></h1> <div style= ...

What steps should I take to ensure that my dropdown menu functions properly?

I am struggling to get my navigation bar with dropdown menus to function properly. I suspect there might be an issue with the CSS code. Can you take a look at it? Here is the HTML code snippet: /*---------------------NAVBAR-------------------*/ ...

Missing Home and Search icons on Jquery mobileNavigationBar

I am having an issue where the Home and search icons are not displaying properly in the output. Instead, they are showing up as hyperlinks. Can someone please help me with this? Here is the code I am using: <meta name="viewport" content="width=device ...

Issue with displaying Bootstrap Tooltip

Recently, I launched a fresh website (currently residing on a sub-domain). However, I am facing an issue with the tooltip not showing up when hovering over the text Get the FinEco Bookmarklet. <span class="bookmarklet"><span class="fa fa-bookmark ...

In R, use mutate to extract the smallest value from the top rows

Recently, I've been struggling with finding the first smaller value within the upper rows of a transformed variable in my data frame. Here's an overview of how my dataframe looks: count 24 33 33 34 35 33 34 35 ... This ta ...

Is there a way to combine vectors of varying lengths without repeating values or resorting to a loop?

Imagine having two vectors with different lengths: v1 <- c("A", "B", "C", "D", "E") v2 <- c("F", "G", "H") The goal is to combine these two vectors without recycling the ...

Moving along the x-axis to prevent any overlap with heterogeneous data when creating forest plots in R

I've been experimenting with creating a forest plot, but I keep encountering an issue where the text for heterogeneity information overlaps with the x-axis of the plot. How can I adjust my code to prevent this overlap from occurring? Essentially, I wa ...

Guide on implementing event listener for right click using pure JavaScript (VANILLA JS)

I need the div to appear wherever the cursor is holding down the right mouse button. In my scenario, I am using the following code: <div class="d-none" id="item"></div> #item{ position: absolute; top: 0; left: 0; w ...

"Need help with resolving issues in my React Bootstrap Navbar? Learn the latest updates on fixing Navbar Brand Collapse here

Having issues with my React.js website navbar created using bootstrap. The menu button doesn't show up when the navbar collapses at a certain point. Can someone spot what's missing in the code below? Tried toggling by following a tutorial, but i ...

The label is not displaying the specified font-family in CSS

Below is a snippet of code that I am having trouble with: testing some content Additionally, here is the CSS code for it: label { font-family: "Andale Mono"; } The issue I am facing is that no matter which font style I try to apply, it does not seem to ...

Tips for centering a div horizontally when it exceeds the width of a mobile screen

My challenge is to create a circular div element that is wider than the mobile screen and perfectly centered. This circular div needs to be an exact circle, specifically targeted for mobile screens. I've attempted to achieve this using the code in th ...

Ensuring grid columns are equal for varying text sizes

I am looking to achieve equal width and spacing for columns without using the width, min-width, max-width properties. Can anyone help me accomplish this using flex or any other method? .d-flex { display: flex; } .d-flex .col { margin: 5px; ...

The HTML and CSS layout is not displaying correctly as planned

I am currently working on a responsive webpage design project. Here is what I have been experimenting with: jsfiddle <div id="container"> <div id="one">#one</div> <div id="two">#two</div> <div id="three">#t ...

Exploring different pages in an Ionic and AngularJS mobile application

I am brand new to the world of Ionic and AngularJS. I have just started working on a simple project but have hit a roadblock. My goal is, To create a login page and a register page. When a user clicks the register button on the login page, they should be ...

What is the best technique for positioning a div using the ELEMENT_NODE method?

  #top { height: .5rem; padding-left: 2.7rem; line-height: .5rem; color: #666; font-size: .12rem; position: relative; background-color: rgb(241, 241, 241); } #top div { position: ...

Enhancing list item appearance by replacing bullets with Font Awesome icons

I need to create a list similar to this example Although I successfully replaced the bullet with a fontawesome icon, the result is not quite right as shown here You may notice a difference in spacing between the two. Here is my CSS code: .custom_list l ...

Leveraging the CSS-Element-Queries Library for emulating the functionality of CSS media queries

Recently, I used a nifty CSS-Element-Queries tool to perform basic element manipulations that trigger whenever the window is resized. In simple terms, my goal was to dynamically adjust an element's attribute based on the current width of the window â ...

Adjust the CSS for the "a" tag's "title" attribute

I am using jquery.fancybox to create an image modal on my website. I have noticed that I can add a description using the title attribute. However, when the description is too long, the text is displayed on a single line and some of it disappears. How can ...

What is the process for defining longitude and latitude as the axes in a ggplot map?

I'm encountering an issue with my code that I just can't seem to pinpoint. My goal is to create a map displaying the coefficients of a geographically weighted regression on the districts of Barcelona. While I can individually plot the points and ...