Modify CSS in Angular Kendo Chart - Customize the style to display line when the value is equal to 0

Is there a way to customize the CSS style of the grid line when the value is zero on my chart?

I'm looking to achieve something similar to this chart:
https://i.sstatic.net/vf5wO.png

Answer №1

If you want to easily adjust the Marker color based on the value of the point, consider setting the color/background/border color property of the series markers to a function instead of a string:

$("#chart").kendoChart({
  series: [ {
    type: "line",
    color: "#82D225",
    markers: {
      visible: true,      
      border: {
        color: function(point){return point.value<=0 ? "red" : "#82D225"; }
      }
    },
    data: [3300, 3200, 0, -300, -100, 200],    
  }]
});

Check out this DEMO for reference.

Changing the color of the line is more complex. You can use a gradient with different colors for values above and below 0:

Create an SVG gradient anywhere on your page:

<div style="height: 0px;">
  <svg>
    <defs>      
      <linearGradient id="theGrad" x1="0" x2="0" y1="0" y2="1">
        <stop stop-color="#82D225" offset="0%"></stop>
        <stop id="stop1" stop-color="#82D225" offset="40%"></stop>
        <stop id="stop2" stop-color="red" offset="40%"></stop>
        <stop stop-color="red" offset="100%"></stop>
      </linearGradient>
    </defs>
  </svg>
</div>  

Then, in the script, find the min and max of your dataset and update the gradient stop offsets:

  var data = [3300, 3200, 0, -300, -100, 200];      
  var max = Math.max(...data);
  var min = Math.min(...data);
  var color = "url(#theGrad)";
  
  var NeedGradient = max > 0 && min <= 0;
  if (NeedGradient){
    var range = max - min;
    var stop = (max - 0) * 100 / range;
    stop = Math.round(stop);
    $("#stop1, #stop2").attr("offset", stop + "%");
  } else {
    max <=0 ? color = "red" : color  = "#82D225";
  }

Finally, apply the gradient to the line on chart render:

$("#chart").kendoChart({
  series: [ {
    type: "line",
    color: function(point){return point.value<=0 ? "red" : "#82D225"; },
    data: data,    
  }],
  render: function(e) {
    $('#chart svg g [clip-path="url(#kdef2)"] path').css("stroke", color);
  }
});

For another example, take a look at this DEMO.

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

The utilization of Display Flex resulting in the enlargement of the containing div

I am currently learning CSS and trying out some new things. I am looking to create a page with two side-by-side divs: one for the sidebar and the other for the main content. My goal is to have the sidebar take up 400px of width and allow the content part t ...

The value from select2 dropdown does not get populated in my article in Angular

I am attempting to link the selected value in a dropdown menu to an article, with a property that matches the type of the dropdown's data source. However, despite logging my article object, the property intended to hold the selected dropdown value app ...

When a StaticFiles instance is mounted, FastAPI will issue a 405 Method Not Allowed response

Running a FastAPI application has been smooth sailing until I encountered an issue. In my current setup, the application script is as follows: import uvicorn from fastapi import FastAPI from starlette.responses import FileResponse app = FastAPI() @app.ge ...

Internet Explorer 10.0.9200 seems to have a tendency to overlook CSS styles

In my web application, I have implemented a 'tab toolbar' with 3 tabs. When a user clicks on a tab, the page displays different data based on which tab is selected. To visually indicate to the user which tab they have clicked on, I dynamically c ...

Improving the appearance of my header on mobile devices

My header needs some improvement, how can I make it look better? Here is the code snippet: 1 Index.php <div class="header"> <div class="headerFont"><a href="index.php">Yo! Yo! Honey Singh..!!</a> </div> <div class="Login ...

"Customize Primeng datatable to automatically adjust height based on content for a

PrimeNG DataTable has a property called [scrollable] that allows for vertical and/or horizontal scrolling. To enable this, you need to set the scrollHeight and/or scrollWidth values. Is it possible to create a table that adjusts its size based on the wind ...

Alignment and spacing that is responsive and inline for unordered lists

Struggling with creating a mobile-responsive navbar, specifically with getting the link containers to resize correctly and centering the text vertically. Attempts with padding and margins haven't yielded results. Bootstrap is being used. In need of a ...

Leveraging Forms for Entering Google Maps Information

Recently, I've been working on an app that aims to generate a custom map based on user input from a form. If you'd like to test the functionality yourself, head over to this page. After filling out all required fields and hitting "Submit", the g ...

`Angular2 - exploring the complexities of function scope`

I'm facing a challenge while working on my Angular2 Sample with the http module. Here is a snippet from my component: app.loginComponent = ng.core.Component({ selector: 'login', templateUrl: 'app/login/login.html&ap ...

Stretching background images on iOS mobile devices

My background is causing issues on iOS devices by stretching only when there is content added to a page like this. However, it loads correctly on empty pages like this. I have tried adding background-attachment:scroll instead of background-size: cover to ...

Having difficulty generating a footer for a page that includes a Material-UI Drawer component

Looking to create a standard full-width footer at the bottom of my page, I need help with the implementation. Utilizing the "Permanent drawer" from Material-UI Drawer for reference here. If you're interested in experimenting with it, CodeSandbox link ...

Adding External Libraries to Angular-CLI: Expanding Your Toolkit with jQuery and Bootstrap

Right now I have to: Install local libraries using npm install bootstrap and npm install jquery Create a folder called src\assets Copy all files from node_modules/bootstrap and node_modules/jquery In index.html <script src="assets/jquery/jquery ...

Troubleshooting Angular Karma Testing: Uncaught ReferenceError - Stripe not recognized

When running tests with karma, I encountered the following error: ReferenceError: Stripe is not defined Component import { Component, OnInit } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { Router } from & ...

Is it possible to integrate Processing JS on top of an HTML element?

I have currently integrated Processing JS with the HTML canvas element on a website. The goal is to have the Processing JS animation run smoothly over the existing HTML elements on the page. You can check out the site at [usandthings.com][1] to get an idea ...

Avoid utilizing PHP with CSS @import as it may not function as intended

Currently, I am experimenting with using HTML/CSS to import PHP files as stylesheets in order to have dynamic stylesheet editing. Although I am new to @import, I need it for switching stylesheets based on the display width of the user's device. Can an ...

Exploring Angular: Grouping Arrays with the groupBy Pipe

import { Pipe, PipeTransform } from '@angular/core'; /* * Group an array by a property (key) * Usage: * value | groupBy : 'field' */ @Pipe({ name: 'groupBy' }) export class GroupByPipe implements PipeTransform { ...

Guide on creating HTML content within a ToolTip function for a table row

I'm working on implementing a tooltip feature that will appear when hovering over a row with extensive HTML content. This feature is intended to be used alongside Foundation framework. However, I am encountering issues getting the tooltip to work prop ...

Can you explain the function of the * CSS operator? Are there any additional CSS operators that serve similar purposes?

While researching how to create a nested table using list elements in CSS, I came across this interesting page: . Upon examining the stylesheet, I noticed unfamiliar symbols being used that appear to be CSS operators, such as the > and * symbols. For ...

Navigating in Angular to initiate file retrieval

Is there a way to set up a route in Angular that allows me to download a file? For example, having a route like '/myFile' would result in downloading the file "/assets/files/test.pdf". I've tried using the redirectTo option for routing, bu ...

How do you transfer byte[] data using a DTO in Java Spring?

I am currently facing an issue with my server-side application. The problem arises when attempting to convert a Blob to an Excel file on the front-end, specifically when the byte[] is sent within a DTO. When sending a POST request from the back-end (sprin ...