3

I am using ngx-charts [Link to Github Repo] for charting purpose in Angular. I am using version 8.x of Angular. This package is really easy to use and comes with good features. But, I can't seem to change the default styling of horizontal bars in horizontal bar chart. Here I am attaching the stackblitz demo which I have tried. I want red border at the bottom of all horizontal bars and also I want the Y-axis data labels above the bars.

Stackblitz Demo of ngx-chart

The problem is that the bars generated are in the svg format. So it gets little bit tricky.

Hope
  • 475
  • 6
  • 16

3 Answers3

5

I am not sure this will help you or not but in my opinion this is one the way to achieve your goal.

there is a stroke-dasharray SVG property for stroke.

for border-bottom I found the solution which i described below:

::ng-deep .ngx-charts .bar {
    stroke: red;
    stroke-dasharray: 0,X,Y,0;
}

Where Y is the value of your bar's Width and the X is the value of sum of Height and width of your bar.

I am sharing a demo of SVG stroke property this is not an ngx chart demo but in my opinion, it will help you if you can get the height and width of your chart element.

https://codepen.io/coderman-401/pen/dyoNgKg

coderman401
  • 582
  • 3
  • 17
3

ngx-chart uses svgs so you can edit them through css:

::ng-deep .ngx-charts .bar {
  stroke: red;
}

Stackblitz demo

Mustahsan
  • 3,852
  • 1
  • 18
  • 34
  • This works! but adds border to whole bar. My problem is that I only want border at bottom. And the bars can be of variable length. So, I can't figure it out. – Hope Feb 25 '20 at 04:23
  • 1
    yes thats the sad part, border cannot be applied to svgs it can only have stroke or outline which will be on all sides not on specific side – Mustahsan Feb 25 '20 at 04:57
2

There is no handle provided for this purpose, but you can always tweak svg like this to get desired changes:

let svgList = <HTMLScriptElement[]><any>document.getElementById(your_parent_Div_id).getElementsByTagName('path');

for (let svg of svgList) {
    event.target.style.stroke = 'black';
    event.target.style.strokeWidth = '4';
}
Marius Jaraminas
  • 813
  • 1
  • 7
  • 19
Amrit
  • 2,115
  • 1
  • 21
  • 41
  • Yeah, That can be a way! but can I apply border through this method? because as far as I know, I can change only stroke, strokewidth, fill, font etc of svg – Hope Feb 24 '20 at 08:00