SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi,

I am able to access the point object in the js fiddle link below.
https://jsfiddle.net/r43tL6j1/2/

However when I am implementing in my local environment the following code isn't working.
tooltip_config.png
tooltip_config.png (22.39 KiB) Viewed 786 times
The code in the ts file is as below.

Code: Select all

import { Component, Input, OnInit, ViewChild } from '@angular/core';
import * as Highcharts from 'highcharts';
import HC_exporting from 'highcharts/modules/exporting';
import HC_Data from 'highcharts/modules/export-data';
import Accessbility from 'highcharts/modules/accessibility';

require('highcharts-grouped-categories')(Highcharts);
import more from 'highcharts/highcharts-more';

more(Highcharts); // init highcharts-more
HC_exporting(Highcharts);
HC_Data(Highcharts);
Accessbility(Highcharts);
Highcharts.AST.allowedAttributes.push('onclick');


Highcharts.AST.allowedAttributes.push('src');
Highcharts.AST.allowedReferences.push('');
Highcharts.AST.allowedAttributes.push('data-value');
Highcharts.AST.allowedReferences.push('tel:');
Highcharts.AST.allowedTags.push('blink');
Highcharts.AST.bypassHTMLFiltering = true;


@Component({
  selector: 'app-stack-column',
  templateUrl: './stack-column.component.html',
  styleUrls: ['./stack-column.component.scss'],
})
export class StackColumnComponent implements OnInit {

  @Input() highChartsData = [
    {
      name: 'Asian',
      pointPadding: 0.01,
      pointWidth: 20,
      opacity: 0.5,
      data: [
        { x: 5, low: 18.4, high: 75.40, low2: 22.10,high2: 66.6,med: 43.2, grey:63.2, color: '#67a6d9' ,name: 'Asian1',},
        { x: 6, low: 26.3, high: 66.4,low2: 53.6,high2: 63.7,med: 59.4, grey:63.2,color: '#f4ae61' ,name: 'Asian2', },
        { x: 7, low: 17.2, high: 81.9,low2: 21.4,high2: 72.8,med: 60.3,grey:63.2, color: '#c79eb9' ,name: 'Asian3', },
        { x: 8, low: 17, high: 31.8,low2: 21.4,high2: 28.7,med: 25.4,grey:63.2, color: '#d35160' ,name: 'Asian4',}
      ],
    }
    
  ];
  Highcharts: typeof Highcharts = Highcharts;
  isHighcharts = typeof Highcharts === 'object';
  updateFlag = false;

  chartConstructor = 'chart';
  @ViewChild('columnChart', { static: false }) columnChart: any;

  chartOptions: any = {};

  constructor() {}

  ngOnInit() {
    this.updateChartOptions();
  }

  updateChartOptions(){
    this.chartOptions = {
      chart: {
        type: 'columnrange',
        width: '400',
  
        events: {
          load: (event: any) => {
            this.loadChart(event.target);
          },
        },
      },
      title: {
        text: 'SC',
        style: {
          display: 'none',
        },
      },
      exporting: {
        enabled: false
      },
  
      xAxis: {
        min: 1,
        max: 12,
        labels: {
          enabled: false,
        },
        tickLength: 0,
        lineColor:'#D1D1D1',
        lineWidth: 1
      },
  
      yAxis: {
        title: {
          text: '',
        },
        min: 0,
        max: 100,
        tickLength: 0,
        labels: {
          format: '{value}%',
        },
        gridLineColor: '#ffffff',
        lineColor:'#D1D1D1',
        lineWidth: 1
      },
      credits: false,
  
      tooltip: {
        // crosshairs: [true, true], 
        valueSuffix: '%',
        useHTML: true,
        formatter: () => {
          const point:any = this;
          console.log('this: ', point);
          console.log('series: ', point.series);
         
        // return `Point (${point.x}, ${point.y}) has color ${point.color}`;
        return`<span>
          <button type="button" onclick="showMoreDetails()">More Details</button>
          </span>`
        },
        style: {
          pointerEvents: 'auto'
        },
      },
  
      plotOptions: {
        columnrange: {},
      },
  
      legend: {
        enabled: true,
      },
  
      series: [
        {
          // name: 'Asian',
          name: this.highChartsData[0].name,
          pointPadding: 0.01,
          pointWidth: 20,
          opacity: 0.5,
          data: this.highChartsData[0].data
        }
        
      ],
    };
  }

 showMoreDetails() {
    console.log('test');
    alert('test');
  };
}
2. The click event in the button is also not working here.
jakub.s
Posts: 1225
Joined: Fri Dec 16, 2022 11:45 am

Re: Appropriate Chart Implementation

Hi,

Could you please send me a demo of this in CodeSandbox or CodePen?

Regards,
Jakub
Jakub
Highcharts Developer
SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi,

The demo for the tooltip with the click event is here. https://codesandbox.io/s/sleepy-wind-ebh3fl

The demo for the tooltip with the point data is here. https://codesandbox.io/s/falling-hooks-fswp0c

We would need a white border around the median as below.
white-border.png
white-border.png (3.92 KiB) Viewed 778 times
User avatar
dawid.d
Posts: 835
Joined: Thu Oct 06, 2022 11:31 am

Re: Appropriate Chart Implementation

Hi,

In terms of creating such an interactive tooltip in Angular, I recommend using portals. In the following topic, you will find an example that provides click event handling and data for a component tooltip in angular: viewtopic.php?f=9&t=50436

I think this should solve both of your problems.

​If you have further inquiries, you may reach out to me at any time.
Best regards!
Dawid Draguła
Highcharts Developer
sanjaysangalge
Posts: 1
Joined: Sat Mar 18, 2023 6:26 pm

Re: Appropriate Chart Implementation

what could be potential cause of below , I am newbie with High chart using angular 14

Error: src/app/overview/sunbrust-chart/sunbrust-chart.component.html:21:1 - error NG8001: 'highcharts-chart' is not a known element:
1. If 'highcharts-chart' is an Angular component, then verify that it is included in the '@Component.imports' of this component.
2. If 'highcharts-chart' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@Component.schemas' of this component to suppress this message.

21 <highcharts-chart></highcharts-chart>
User avatar
dawid.d
Posts: 835
Joined: Thu Oct 06, 2022 11:31 am

Re: Appropriate Chart Implementation

Hello sanjaysangalge,

Welcome to our forum and thanks for contacting us with your question!

It's hard to say without seeing your code, but basically, it's not recognizing the highcharts-chart tag as a component. Could you post a demo (created e.g. in Stackblitz or Codesandbox) where I can see your code to identify the source of the error?

I'm waiting for your reply
Best regards!
Dawid Draguła
Highcharts Developer
SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi,

We have an issue where the highcharts-legend doesn't get properly aligned to the data points.

We would like to apply a generic css so that the legend gets aligned to all the containers.
Could you please help us out on this.

[attachment=0]alignment.png[/attachment]

Moreover we would also want to chart responsive. Do you suggest using the responsive behaviour of highcharts together with bootstrap.

(For eg. At a particular resolution we would like to show 3 in a row but when zoomed in we would like 4 )

[attachment=1]zoomed_in.png[/attachment]
Attachments
zoomed_in.png
zoomed_in.png (17.5 KiB) Viewed 703 times
alignment.png
alignment.png (25.9 KiB) Viewed 706 times
jakub.s
Posts: 1225
Joined: Fri Dec 16, 2022 11:45 am

Re: Appropriate Chart Implementation

Hi,

1. I'm sorry but I don't think I can see the legend anywhere. But you can do this like in the demo that I've previously sent you: https://jsfiddle.net/BlackLabel/ahn9w51q/ where you can adjust all the parameters yourself.

2. If you want your columns to be responsive, you can handle an additional case in chart.events.render where you'll check:
- if the "higher opacity rectangle" doesn't exist yet, render it for the first time
- if the "higher opacity rectangle" exists, move it to correct position

Here's a simplified demo: https://jsfiddle.net/BlackLabel/7x6ckL1o/
If you experiment it you'll notice that the width of the chart container can change, but the column with the custom-rendered SVG elements are still in the right place.

3. When it comes to positioning the charts next to each other in rows/columns, I don't think it's directly related to Highcharts. You could use CSS Grid (you can read more about this here: https://css-tricks.com/snippets/css/com ... uide-grid/) to achieve something like this: https://jsfiddle.net/BlackLabel/7yL12ta5/

Try to change the width of the screen to see that the number of column changes (thanks to the @media query and CSS Grid).

Please let me know if that helps!
Jakub
Highcharts Developer
SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi Team,

We would like to add the following description to the points at different intervals.

Could you please share a demo of how the customization of the svgs could be done to achieve the below.
more-info.png
more-info.png (47.27 KiB) Viewed 599 times
jakub.s
Posts: 1225
Joined: Fri Dec 16, 2022 11:45 am

Re: Appropriate Chart Implementation

Hi,

Thanks for the question!

To render custom elements like these you should use the SVGRenderer. With SVGRenderer you can render SVGElements like:
- rectangles
- circles
- texts
- labels (with background)
- symbols (png/gif/SVGs)
- paths

So, literally, you can draw anything in your Highcharts container.

The method we usually use to make everything responsive is the following:
1. We usually render additional SVG elements after each chart render (first load of the chart + each resize of the chart's container). To do that, we use chart.events.render.

2. During the first render (after the initial load), we draw the SVG elements for the first time.

3. For each following render (after resize or update) we need to update the x, y, width, height of the custom SVG elements so that our chart is responsive. We do this with SVGElement.attr({ attribute: newValue });. Here's the API: https://api.highcharts.com/class-refere ... ement#attr

So, I see it this way:
- you can draw the rectangles with renderer.rect
- you can draw the texts with renderer.text
- you can draw the icons with renderer.symbol (https://api.highcharts.com/class-refere ... rer#symbol)
If you position everything correctly you'll easily get the result from the attached image.

Knowing the bounding boxes of your custom SVG elements might be helpful with positioning them relatively to each other so you might want to use the SVGElement.getBBox() method which returns an object with width, height, x, y (https://api.highcharts.com/class-refere ... nt#getBBox)

I've prepared a simple demo with one of your custom elements which should give you an idea of how to achieve your result with additional icons: https://jsfiddle.net/BlackLabel/jr3L927s/

Everything there is fully responsive.

Please let me know if you encounter any problems with your implementation.

Best regards!
Jakub
Highcharts Developer
SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi,

Thanks for the information.
I am now able to get the svg implemented in my local. However could you please help on the following observations.

1. We are using icons from a third party package and while placing the icons in the text part of the renderer(using span) isn't working.
arrow-down.png
arrow-down.png (3.98 KiB) Viewed 559 times
The attachment people.png is no longer available
Suppose if these are the two png images we use, could you please update the link https://jsfiddle.net/BlackLabel/jr3L927s/ on how to place this inline.


2. I did check on the renderer.symbol for getting the below implemented. Can we use predefined symbol - triangle to achieve the below.
triangle.png
triangle.png (5.46 KiB) Viewed 559 times

3. I tried using renderer.path for the below median line but we would need to show the svg with the details at the right of the line as below again.
median_line.png
median_line.png (7.49 KiB) Viewed 559 times
It would be really great if you could update the link with the above changes, https://jsfiddle.net/BlackLabel/jr3L927s/
jakub.s
Posts: 1225
Joined: Fri Dec 16, 2022 11:45 am

Re: Appropriate Chart Implementation

Hi,

1. Did you include this image in your demo? I couldn't find it anywhere. Also, I think that something is wrong with the attachement. But when it comes to adding your custom icons you can simply do this with renderer.symbol. Demo: https://jsfiddle.net/BlackLabel/xy1b9zpq/

2. You can easily add a triangle like this with renderer.path. Here's a demo: https://jsfiddle.net/BlackLabel/02zeru86/

3. Again, you can use the renderer.path to draw a line. If you struggle with creating a path, you might find this resource helpful: https://yqnn.github.io/svg-path-editor/

Here's a demo: https://jsfiddle.net/BlackLabel/h03mdu75/

Best regards!
Jakub
Highcharts Developer
SunilReddy87
Posts: 18
Joined: Wed Feb 22, 2023 12:09 am

Re: Appropriate Chart Implementation

Hi,

Thanks for your reply. I am now able to include the images with the relative path and also render the svg of rectangle and triangles.

However I would need the know the axis endpoints to draw the below path. The start of the path is ideally the point where the dotted line of axis appear and the end would be the point where the dotted line of the axis end.
median_line_SVG.png
median_line_SVG.png (6.96 KiB) Viewed 500 times
On hover of the Rect svg that we have drawn, we would need to show a path pendicular path from the median path that we draw as above to the point where we specify the other percentile values.
perpendicular.png
perpendicular.png (9.05 KiB) Viewed 500 times
Could you please help in getting this implemented.

The entire chart would be looking as below. (FYI)
entire-svg.png
entire-svg.png (16.28 KiB) Viewed 500 times
jakub.s
Posts: 1225
Joined: Fri Dec 16, 2022 11:45 am

Re: Appropriate Chart Implementation

Hi,

1. Here's a demo showing positions of the x-axis start and end: https://jsfiddle.net/BlackLabel/x9kf4ps8/

2. You can achieve this with the SVGRenderer:
- create a rect
- add an event (mouseover, mouseout),
- draw/remove a path after a certain event
Here's a demo: https://jsfiddle.net/BlackLabel/7bf6jn35/

Let me know if that helps!

Kind regards!
Jakub
Highcharts Developer

Return to “Highcharts Usage”