adds SliceStyle for pie chart.
This commit is contained in:
parent
df971b61d1
commit
88b6b2274d
|
@ -31,13 +31,11 @@ Two axis:
|
|||
|
||||
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/two_axis.png)
|
||||
|
||||
Simple Moving Average:
|
||||
# Other Chart Types
|
||||
|
||||
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/ma_goog_ltm.png)
|
||||
Pie Chart:
|
||||
|
||||
Bollinger Bounds:
|
||||
|
||||
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/spy_ltm_bbs.png)
|
||||
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/pie_chart.png)
|
||||
|
||||
# Code Examples
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
pie := chart.PieChart{
|
||||
Width: 512,
|
||||
Height: 512,
|
||||
Canvas: chart.Style{
|
||||
FillColor: chart.ColorLightGray,
|
||||
},
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 36 KiB |
19
pie_chart.go
19
pie_chart.go
|
@ -18,6 +18,7 @@ type PieChart struct {
|
|||
|
||||
Background Style
|
||||
Canvas Style
|
||||
SliceStyle Style
|
||||
|
||||
Font *truetype.Font
|
||||
defaultFont *truetype.Font
|
||||
|
@ -214,14 +215,28 @@ func (pc PieChart) styleDefaultsPieChartValue() Style {
|
|||
}
|
||||
|
||||
func (pc PieChart) stylePieChartValue(index int) Style {
|
||||
return Style{
|
||||
return pc.SliceStyle.InheritFrom(Style{
|
||||
StrokeColor: ColorWhite,
|
||||
StrokeWidth: 5.0,
|
||||
FillColor: GetAlternateColor(index),
|
||||
FontSize: 24.0,
|
||||
FontSize: pc.getScaledFontSize(),
|
||||
FontColor: ColorWhite,
|
||||
Font: pc.GetFont(),
|
||||
})
|
||||
}
|
||||
|
||||
func (pc PieChart) getScaledFontSize() float64 {
|
||||
effectiveDimension := MinInt(pc.GetWidth(), pc.GetHeight())
|
||||
if effectiveDimension >= 2048 {
|
||||
return 48.0
|
||||
} else if effectiveDimension >= 1024 {
|
||||
return 24.0
|
||||
} else if effectiveDimension > 512 {
|
||||
return 18.0
|
||||
} else if effectiveDimension > 256 {
|
||||
return 12.0
|
||||
}
|
||||
return 10.0
|
||||
}
|
||||
|
||||
func (pc PieChart) styleDefaultsBackground() Style {
|
||||
|
|
Loading…
Reference in New Issue
Block a user