Steps for incorporating a storyline into a CSS Chart

I'm attempting to introduce a horizontal line at a specific point using chartscss.org

For instance, on the given chart utilizing Charts CSS below, I'm aiming to include a horizontal line at 15.5... Similar to the illustration shown.

I've experimented with various approaches such as adjusting the chart's position: relative and incorporating an absolute over the chart but am uncertain about how exactly to position it at 15.5 considering the chart/values provided.

tbody {
  min-height: 450px;
}
<link href="https://cdn.jsdelivr.net/npm/charts.css/dist/charts.min.css" rel="stylesheet"/>
<table class="charts-css column show-labels data-spacing-10" id="my-chart">
  <thead>
    <tr>
      <th scope="col">Stat</th>
      <th scope="col">Value</th>
    </tr>
  </thead>

  <tbody class="position-relative mb-4">
    <tr>
      <th>1/14</th>
      <td style="--size: 0.48; --color: #bc2e2f">12</td>
    </tr>
    <tr>
      <th>1/15</th>
      <td style="--size: 0.84; --color: #27ae60">21</td>
    </tr>
    <tr>
      <th>1/19</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/24</th>
      <td style="--size: 0.48; --color: #bc2e2f">12</td>
    </tr>
    <tr>
      <th>1/27</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/29</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/31</th>
      <td style="--size: 0.56; --color: #bc2e2f">14</td>
    </tr>
    <tr>
      <th>2/4</th>
      <td style="--size: 0.96; --color: #27ae60">24</td>
    </tr>
    <tr>
      <th>2/5</th>
      <td style="--size: 0.52; --color: #bc2e2f">13</td>
    </tr>
    <tr>
      <th>2/7</th>
      <td style="--size: 0.56; --color: #bc2e2f">14</td>
    </tr>
    <tr>
      <th>2/9</th>
      <td style="--size: 0.4; --color: #bc2e2f">10</td>
    </tr>
    <tr>
      <th>2/11</th>
      <td style="--size: 0.68; --color: #27ae60">17</td>
    </tr>
    <tr>
      <th>2/12</th>
      <td style="--size: 0.72; --color: #27ae60">18</td>
    </tr>
    <tr>
      <th>2/16</th>
      <td style="--size: 0.68; --color: #27ae60">17</td>
    </tr>
    <tr>
      <th>2/24</th>
      <td style="--size: 1; --color: #27ae60">25</td>
    </tr>
  </tbody>
</table>

https://i.sstatic.net/MhwLv.png

Answer №1

Are you satisfied with this outcome?

:root {
  --value-scale: calc(450px / 25);
}

tbody {
  min-height: 450px;
  position: relative;
}

tbody::before {
  content: "";
  position: absolute;
  top: calc(var(--value-scale) * 15.5 + 1px);
  left: 0;
  right: 0;
  border-top: 2px solid blue;
  z-index: 1;
}
<link href="https://cdn.jsdelivr.net/npm/charts.css/dist/charts.min.css" rel="stylesheet"/>
<table class="charts-css column show-labels data-spacing-10" id="my-chart">
  <thead>
    <tr>
      <th scope="col">Stat</th>
      <th scope="col">Value</th>
    </tr>
  </thead>

  <tbody class="position-relative mb-4">
    <tr>
      <th>1/14</th>
      <td style="--size: 0.48; --color: #bc2e2f">12</td>
    </tr>
    <tr>
      <th>1/15</th>
      <td style="--size: 0.84; --color: #27ae60">21</td>
    </tr>
    <tr>
      <th>1/19</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/24</th>
      <td style="--size: 0.48; --color: #bc2e2f">12</td>
    </tr>
    <tr>
      <th>1/27</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/29</th>
      <td style="--size: 0.64; --color: #27ae60">16</td>
    </tr>
    <tr>
      <th>1/31</th>
      <td style="--size: 0.56; --color: #bc2e2f">14</td>
    </tr>
    <tr>
      <th>2/4</th>
      <td style="--size: 0.96; --color: #27ae60">24</td>
    </tr>
    <tr>
      <th>2/5</th>
      <td style="--size: 0.52; --color: #bc2e2f">13</td>
    </tr>
    <tr>
      <th>2/7</th>
      <td style="--size: 0.56; --color: #bc2e2f">14</td>
    </tr>
    <tr>
      <th>2/9</th>
      <td style="--size: 0.4; --color: #bc2e2f">10</td>
    </tr>
    <tr>
      <th>2/11</th>
      <td style="--size: 0.68; --color: #27ae60">17</td>
    </tr>
    <tr>
      <th>2/12</th>
      <td style="--size: 0.72; --color: #27ae60">18</td>
    </tr>
    <tr>
      <th>2/16</th>
      <td style="--size: 0.68; --color: #27ae60">17</td>
    </tr>
    <tr>
      <th>2/24</th>
      <td style="--size: 1; --color: #27ae60">25</td>
    </tr>
  </tbody>
</table>

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

Responsive on Mobile Devices

I'm seeking assistance in brainstorming a creative idea or method to convert the carousel indicators into a menu, or any alternative approach to ensure the entire section is mobile responsive while keeping all the indicators visible within the mobile ...

Encountering a problem with Material UI where the drop-down options are appearing below the footer of the modal window

Hey there, I'm currently using Material UI and React Select. One issue I've run into is that my dropdown options are appearing below the modal window. You can check out the code sandbox demo here https://i.sstatic.net/Av6Pe.jpg I've tried ...

The blur function in jQuery is not functioning as expected

I'm facing an issue where only the first of my 3 .blur's is working. Here is the jQuery code snippet: <script type='text/javascript'> $(document).ready(function() { $("#user_name").blur(function() { if ($( ...

Guide on implementing CSS3 parser with HtmlUnitDriver

As an example, let's consider a scenario where we have a selector to target the active menu item: $("ul#menu li a[href='/']") And a selector to target the remaining menu items (1): $("ul#menu li a:not([href='/'])") However, the ...

Why doesn't "align-self: flex-end" relocate the game board to the bottom of the screen?

Hey there, I am currently working on developing a Connect 4 game and have decided to use a table for the board. To position the board properly, I am utilizing flexbox. Although I have specified align-items as 'flex-end' in order to bring it to th ...

What is the method for incorporating jQuery UI effects into buttons that are imported from a basic HTML document?

I am continuously updating the content on my website in three distinct ways: 0) Utilizing jQuery's getJSON('bla.json') to read JSON files; 1) Fetching JSONized C#/Razor classes via jQuery's getJSON('bla.cshtml'); 2) Loading H ...

What is the best way to enable my search function to filter out specific items from a table?

Currently, I have created a table populated with data fetched from a JSON file. Now, my focus is on implementing a search functionality that filters out items based on user input and displays only those table rows matching the search criteria. The code sni ...

Safari browser not supporting CSS @property --rotate functionality

This card's animation is functioning well in Chrome, but it is not compatible with Safari and Mozilla Firefox. I suspect the issue lies with the @property --rotate, as it is no longer supported by Safari. Therefore, I am searching for an alternative ...

Why does my chart.js disappear every time I perform a new render?

Hey there, I'm facing an issue with my code. Let me paste what I have... import React, { memo, useEffect } from 'react'; import Chart from "chart.js"; /* redux-hook */ import { useSelector } from 'react-redux' const lineChart = m ...

Using CSS and JavaScript to hide a div element

In my one-page website, I have a fixed side navigation bar within a div that is initially hidden using the display:none property. Is there a way to make this side nav appear when the user scrolls to a specific section of the page, like when reaching the # ...

The UL list-style does not seem to be working properly on the Woocommerce checkout page

After creating my e-commerce website and implementing the woocommerce plugin to display products, I encountered an issue. The main menu pages are all showing up with the list-style, but the pages associated with the plugins are not displaying the list-styl ...

What does the term "root element" refer to in the Material-UI documentation?

I am finding the terminology used in material ui confusing and would appreciate if someone could clarify it for me. For example, let's consider this information from https://material-ui.com/guides/api/: Spread Undocumented properties supplied ar ...

Incorporate an external JavaScript script using code

I'm currently working on integrating a map widget from 'Awesome Table' into the codebase of an open-source CRM platform. The specific code snippet I need to add is <div data-type="AwesomeTableView" data-viewID="-KLtnY5OHJPgnEOX1bKf"> ...

"Make your slides smooth and responsive with the unslick option in slick

Currently implementing the Slick Slider on a WordPress website. The slider is designed to display 3 columns at a screen size of 1024px and above. When the screen size drops below 1024px, the slider adjusts to show 2 columns, and on mobile devices, it swit ...

Denied rendering of design due to incompatible MIME type

Just delved into the world of node / express and decided to test my skills by creating a simple tip calculator app. However, I seem to have hit a roadblock with loading my CSS. The console keeps throwing this error: "Refused to apply style from &apos ...

Showing data in a grid format on a webpage

I created a Java program that generates an array list with values such as Hi, Hello, How, Are, You, Me, They, and Them. In addition, I developed a basic controller to convert these values into JSON format and display them on localhost:8090/greeting like t ...

Is it advisable to store JSON data in data params instead of making an AJAX call?

Previously, I stored my component data within the element's data parameter. Should I continue doing this or switch to using an Ajax call to fetch the data? 1. Using data parameter: <a href="#" data-core="{JSON-data}" id="item-1"> <a href ...

CSS - owl carousel automatically stretches images to full width

Here is the code snippet that I am working with: $(document).ready(function() { $('.owl-carousel').owlCarousel({ loop:true, items:4, autoplay:true, autoplayTimeout:2000, autoplayHoverPause:true }); }); #owl-demo ...

Mobile Menu in wordpress stays visible after being clicked

I recently created a one-page layout that includes some links. However, when I view the site on my smartphone and open the main menu using the button to click on a link (which scrolls within the same page), I noticed that the mobile menu remains visible a ...

The font face feature does not seem to be functioning properly in the IE browser

I'm facing an issue with font face in a jQuery popup. It seems to be working fine on Chrome and Firefox, but it's not rendering properly on IE browsers. Font Face Code in css ---------------------- @font-face { font-family: "pt-sans"; sr ...