Target/ goal line implementation
Closed this issue · 5 comments
1Jesper1 commented
Hello, nice project! I would like to ask if it's possible to implement a target line/ goal line in the gauge chart.
Something like this: https://plnkr.co/edit/25KSME35LewdkQaybBc5?p=preview
1Jesper1 commented
Just a start:
export function drawTargetLine(
svg,
chartHeight: number,
offset: number,
needleColor: string,
centralLabel: string,
outerRadius: number,
targetLine: number,
outerNeedle: boolean,
) {
// Different circle radiuses in the base of needle
let innerGaugeRadius =
centralLabel || outerNeedle ? chartHeight : chartHeight * 0.1
let gaugeArc = arc()
.innerRadius(innerGaugeRadius)
.outerRadius(outerRadius)
.startAngle(perc2RadWithShift(targetLine))
.endAngle(perc2RadWithShift(targetLine + 1))
// White needle base if something should be written on it, gray otherwise
svg
.append('path')
.attr('d', gaugeArc)
.attr('fill', centralLabel || outerNeedle ? needleColor : needleColor)
.attr(
'transform',
'translate(' +
(chartHeight + offset * 2) +
', ' +
(chartHeight + offset) +
')',
)
.attr('class', 'bar')
}
greetclock commented
@1Jesper1 thank you, it's a nice idea. We will discuss it and then implement. I'll ping you when it's done.
1Jesper1 commented
Sounds great! @cherurg Adding a target line value label would also be handy.