adds SliceStyle for pie chart.

This commit is contained in:
Will Charczuk 2016-07-28 19:17:35 -07:00
parent df971b61d1
commit 88b6b2274d
4 changed files with 22 additions and 7 deletions

View File

@ -31,13 +31,11 @@ Two axis:
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/two_axis.png) ![](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/pie_chart.png)
![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/images/spy_ltm_bbs.png)
# Code Examples # Code Examples

View File

@ -10,6 +10,8 @@ import (
func drawChart(res http.ResponseWriter, req *http.Request) { func drawChart(res http.ResponseWriter, req *http.Request) {
pie := chart.PieChart{ pie := chart.PieChart{
Width: 512,
Height: 512,
Canvas: chart.Style{ Canvas: chart.Style{
FillColor: chart.ColorLightGray, FillColor: chart.ColorLightGray,
}, },

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -18,6 +18,7 @@ type PieChart struct {
Background Style Background Style
Canvas Style Canvas Style
SliceStyle Style
Font *truetype.Font Font *truetype.Font
defaultFont *truetype.Font defaultFont *truetype.Font
@ -214,14 +215,28 @@ func (pc PieChart) styleDefaultsPieChartValue() Style {
} }
func (pc PieChart) stylePieChartValue(index int) Style { func (pc PieChart) stylePieChartValue(index int) Style {
return Style{ return pc.SliceStyle.InheritFrom(Style{
StrokeColor: ColorWhite, StrokeColor: ColorWhite,
StrokeWidth: 5.0, StrokeWidth: 5.0,
FillColor: GetAlternateColor(index), FillColor: GetAlternateColor(index),
FontSize: 24.0, FontSize: pc.getScaledFontSize(),
FontColor: ColorWhite, FontColor: ColorWhite,
Font: pc.GetFont(), 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 { func (pc PieChart) styleDefaultsBackground() Style {