fix: fix zero value of funnel chart, #43
This commit is contained in:
parent
8ba9e2e1b2
commit
d3f7a773af
2 changed files with 15 additions and 2 deletions
|
|
@ -30,6 +30,8 @@ func main() {
|
||||||
60,
|
60,
|
||||||
40,
|
40,
|
||||||
20,
|
20,
|
||||||
|
10,
|
||||||
|
0,
|
||||||
}
|
}
|
||||||
p, err := charts.FunnelRender(
|
p, err := charts.FunnelRender(
|
||||||
values,
|
values,
|
||||||
|
|
@ -40,6 +42,8 @@ func main() {
|
||||||
"Visit",
|
"Visit",
|
||||||
"Inquiry",
|
"Inquiry",
|
||||||
"Order",
|
"Order",
|
||||||
|
"Pay",
|
||||||
|
"Cancel",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,21 @@ func (f *funnelChart) render(result *defaultRenderResult, seriesList SeriesList)
|
||||||
widthList := make([]int, len(seriesList))
|
widthList := make([]int, len(seriesList))
|
||||||
textList := make([]string, len(seriesList))
|
textList := make([]string, len(seriesList))
|
||||||
seriesNames := seriesList.Names()
|
seriesNames := seriesList.Names()
|
||||||
|
offset := max - min
|
||||||
for index, item := range seriesList {
|
for index, item := range seriesList {
|
||||||
value := item.Data[0].Value
|
value := item.Data[0].Value
|
||||||
widthPercent := (value - min) / (max - min)
|
// 最大最小值一致则为100%
|
||||||
|
widthPercent := 100.0
|
||||||
|
if offset != 0 {
|
||||||
|
widthPercent = (value - min) / offset
|
||||||
|
}
|
||||||
w := int(widthPercent * float64(width))
|
w := int(widthPercent * float64(width))
|
||||||
widthList[index] = w
|
widthList[index] = w
|
||||||
percent := value / max
|
// 如果最大值为0,则占比100%
|
||||||
|
percent := 1.0
|
||||||
|
if max != 0 {
|
||||||
|
percent = value / max
|
||||||
|
}
|
||||||
textList[index] = NewFunnelLabelFormatter(seriesNames, item.Label.Formatter)(index, value, percent)
|
textList[index] = NewFunnelLabelFormatter(seriesNames, item.Label.Formatter)(index, value, percent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue