Merge pull request #103 from martinlindhe/linechart-fix-x-label-dynamic-data

linechart: remember if data labels were automatically calculated
This commit is contained in:
Zack Guo 2016-10-25 12:17:03 -04:00 committed by GitHub
commit c1c69b79dd

View File

@ -69,6 +69,7 @@ type LineChart struct {
labelYSpace int labelYSpace int
maxY float64 maxY float64
minY float64 minY float64
autoLabels bool
} }
// NewLineChart returns a new LineChart with current theme. // NewLineChart returns a new LineChart with current theme.
@ -211,7 +212,8 @@ func (lc *LineChart) calcLabelY() {
func (lc *LineChart) calcLayout() { func (lc *LineChart) calcLayout() {
// set datalabels if it is not provided // set datalabels if it is not provided
if lc.DataLabels == nil || len(lc.DataLabels) == 0 { if (lc.DataLabels == nil || len(lc.DataLabels) == 0) || lc.autoLabels {
lc.autoLabels = true
lc.DataLabels = make([]string, len(lc.Data)) lc.DataLabels = make([]string, len(lc.Data))
for i := range lc.Data { for i := range lc.Data {
lc.DataLabels[i] = fmt.Sprint(i) lc.DataLabels[i] = fmt.Sprint(i)