Achieving the highest ranking for Kendo chart series item labels

Currently, I am working with a Kendo column chart that has multiple series per category.

My goal is to position Kendo chart series item labels on top regardless of their value. By default, these labels are placed at the end of each chart item, appearing on top of columns for positive values and at the bottom for negatives.

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

app.component.html

<kendo-chart>
  <kendo-chart-category-axis>
    <kendo-chart-category-axis-item [labels]="{ margin: { top: 10 } }">
    </kendo-chart-category-axis-item>
  </kendo-chart-category-axis>

  <kendo-chart-value-axis>
    <kendo-chart-value-axis-item>
    </kendo-chart-value-axis-item>
  </kendo-chart-value-axis>

  <kendo-chart-series>
    <kendo-chart-series-item *ngFor="let groupedResult of groupedData"
                            [data]="groupedResult.items"
                            field="income"
                            type="column"
                            categoryField="clientName"
                            noteTextField="income">
      <kendo-chart-series-item-labels format="C0">
      </kendo-chart-series-item-labels>
      <kendo-chart-series-item-notes position="bottom"
                                     [icon]="{ visible: false }"
                                     [line]="{ width: 0 }"
                                     [label]="noteLabel">
      </kendo-chart-series-item-notes>
    </kendo-chart-series-item>
  </kendo-chart-series>
</kendo-chart>

app.component.ts

import { Component, OnInit } from '@angular/core';
import * as _ from 'lodash';

export type TrendItem = {
  clientName: string;
  year: number;
  period: number;
  income: number;
};

export type GroupedTrendItem = {
  value: { year: number; period: number };
  items: TrendItem[];
};

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
  public trendItems: TrendItem[] = [
    {
      clientName: 'Client1',
      year: 2020,
      period: 3,
      income: -35,
    },
    {
      clientName: 'Client1',
      year: 2020,
      period: 4,
      income: 40,
    },
    {
      clientName: 'Client2',
      year: 2020,
      period: 1,
      income: -15,
    },
    {
      clientName: 'Client2',
      year: 2020,
      period: 2,
      income: 20,
    },
    {
      clientName: 'Client2',
      year: 2020,
      period: 3,
      income: 15,
    },
    {
      clientName: 'Client3',
      year: 2020,
      period: 2,
      income: 50,
    },
    {
      clientName: 'Client3',
      year: 2020,
      period: 3,
      income: -35,
    },
    {
      clientName: 'Client3',
      year: 2020,
      period: 4,
      income: 20,
    },
  ];

  public noteLabel = {
    color: 'black',
    content: e => `Q${e.dataItem.period} ${e.dataItem.year}`,
    font: '12px Arial',
    margin: -30,
  };

  private getGroupedTrends() {
    const groupedTrendItems = this.trendItems.reduce((acc, trendItem) => {
      let element = acc.find(el => el.value.year === trendItem.year
        && el.value.period === trendItem.period
      );

      if (element) {
        element.items.push(trendItem);
      } else {
        acc.push({
          value: { year: trendItem.year, period: trendItem.period },
          items: [trendItem],
        });
      }
      return acc;
    }, [] as GroupedTrendItem[]);

    return _.sortBy(groupedTrendItems, [
      item => item.value.year,
      item => item.value.period,
    ]);
  }

  public groupedData = this.getGroupedTrends();

  public ngOnInit() {
    console.log(this.groupedData);
  }
}

You can test this code by clicking here.

Currently, the labels do not offer an available 'top' option for the SeriesLabelsPosition component when working with a column chart (although the reason for this remains unclear to me). If the period display is not necessary, the SeriesNotesComponent can be used as I currently employ it for periods, allowing for the assignment of position="top" without any issues.


Therefore, my question is how to ensure labels are always displayed on top of the column regardless of their value.

Answer №2

With SeriesNoteLabel, you have the ability to include a new line when merging period and cost. I have created a sample on Stackblitz for you to check out here.

content: e => `Q${e.dataItem.period} ${e.dataItem.year} \n ${this.currencyPipe.transform(e.dataItem.income)}`,

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

Ways to eliminate all characters preceding a certain character within an array dataset

I am currently working on parsing a comma-separated string retrieved from a web service in my application, which contains a list of user roles. My goal is to convert this string into an array using jQuery, and I have successfully achieved that. However, I ...

Solving issues with event handling through addEventListener within a functional component in React

I am working on a React component that includes an input field and I want to implement a character autocompletion feature. The idea is that when a user types " or ', the same character should be automatically added again, with the cursor placed i ...

Django: The Art of Rejuvenating Pages

Consider the following code snippet which updates the timestamp of a database model whenever it is accessed: def update_timestamp(request): entry = Entry.objects.filter(user=request.user) entry.update(timestamp=timezone.now()) return HttpRespo ...

Sorting in reverse order within a table

Is there a way to reverse the order in which my function renders table rows with incremental id? (first row with id=n, last with 1) Here is the code snippet I am using: renderRows = () => { const { receipts } = this.props const reversedReceipt ...

Organize a list using custom span values with JavaScript

<ul id="CoreWebsiteTopHeader_6_list"><li><a class="navigation" href="/seller"><span class="editableLinks" data-id="32638" data-sort="110">Seller</span></a></li><li><a class="navigation" href="/about">&l ...

JavaScript-based tool for extracting content from Sketch file

My goal is to extract the contents of a .sketch file. I have a file named myfile.sketch. When I rename the file extension to myfile.zip and extract it in Finder, I can see the files inside. However, when I try the same process on the server using Node.js ...

Failed Attempt to Execute React Native Application using Command Prompt (iOS)

I'm currently working through the React Native tutorial found on their official website. During my project building process, I utilized the following command: react-native run-ios An error was encountered: Found Xcode project TestProject.xcodeproj ...

Incorporate Data-table functionality into an Ionic 3 application

After building a website with Ionic 3, I am interested in incorporating a data table similar to the one showcased here. What steps should I take to integrate this library into my website? Are there any particular considerations for the Ionic/Angular env ...

Cross-origin resource sharing (CORS) allows for the secure transfer of data across different

Currently, I am faced with a challenge in making an XmlHTTPRequest POST request from a page loaded via HTTPS to a different domain using an HTTP URL. The HTTP server in question is local and does not support HTTPS due to being within a home setup (like a s ...

Prevent user input when an alert window is open

Users keep pressing the enter key multiple times when an alert box pops up, causing them to accidentally dismiss the message by hitting 'ok'. Is there a simple way to prevent key presses on alert windows and only allow mouse input? ...

Incorporating transitions within a styled component using @emotion/core

I'm currently working on adding a smooth transition effect when a button is clicked. The code that adjusts the isOpen property is functioning correctly. However, I'm facing an issue where instead of animating, the content just flips abruptly. I a ...

Using Javascript to iterate through and increase HTML code with values all the way up to 55

I am looking for a way to automatically generate a list of links in an HTML page using JavaScript. I have tried a few scripts, but none have worked for me. This is the current structure of my HTML... <a href="1.html"><img src="images/1.jpg" widt ...

Instructions for adding an onfocus event listener to an input field in order to dynamically change the formatting of associated labels

I'm looking to change the style of my input labels to a more fancy look by implementing the .fancyclass style when using the onfocus event on the input field. I am curious to know how this can be achieved through event listeners in Javascript? ...

The installed local Angular version is outdated compared to the current project version

I've been having trouble customizing my Angular CLI because a package I need only works with an older version of Angular. Currently, my global Angular version is 15.2.9. However, when I create a new Angular project using ng new, the package.json shows ...

What could be causing the DATE_SUB function to fail in executing a MySQL query through Node.js?

I am encountering an issue with a datetime field in a MySQL database table on Planetscale. My goal is to subtract some time from the datetime value using the DATE_SUB function. While this operation works smoothly in the database console on Planetscale&apos ...

Are there any alternative solutions to the onunload event in Chrome, or any other ways to achieve the

After extensive searching for a solution to this issue, including scouring Google Chrome support sites and the Chrome Bug Issues page where the problem has not yet been resolved. Currently, I find myself in a situation where I need to use the onload or onb ...

Using mousedown, mousemove, and mouseup to handle touch events in vanilla JavaScript instead of jQuery

Can someone guide me on how to set up a touch event handler in JavaScript using the mousedown, mousemove, and mouseup events? I would really appreciate any suggestions or tips! ...

What are the best methods for testing a function containing multiple conditional statements?

I have a complex function that I want to showcase here, it's quite simple but for some reason, I'm struggling with writing unit tests for it. I don't need the exact unit test implementation, just a general approach or tips on how to handle i ...

What is the best method for dividing a user interface into several arrays of keys, each grouped by type?

Given a simple structure: structure IPerson { firstName: string; lastName: string; age: number; city: string; favoriteNumber: number; isMarried: boolean; hasDriverLicense: boolean; } How do I create arrays containing keys grouped by data typ ...

Exploring the connected component feature in React/Redux

While testing the connected component of my React/Redux app, I encountered an error. The test case that caused the error is: App component › shows account info and debits and credits` Invariant Violation: Could not find "store" in either the context or ...