gochart/chart_parser_pie.go

51 lines
1021 B
Go
Raw Permalink Normal View History

package main
import (
"github.com/zieckey/goini"
"strings"
)
type PieChart int
2017-03-16 16:44:58 +08:00
func (c *PieChart) Parse(ini *goini.INI, file string) (map[string]string, error) {
args := make(map[string]string)
args["ChartType"], _ = ini.Get("ChartType")
args["Title"], _ = ini.Get("Title")
args["SubTitle"], _ = ini.Get("SubTitle")
args["SeriesName"], _ = ini.Get("SeriesName")
2017-03-16 16:44:58 +08:00
/* Generate DataArray:
[
['Firefox', 45.0],
['IE', 26.8],
['Chrome', 12.8],
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
*/
DataArray := "[\n"
2017-03-16 16:44:58 +08:00
mapkeys, kvmap, err := LoadConfGetOrderMap(file)
if err != nil {
return nil, err
}
for _, k := range mapkeys {
if !strings.HasPrefix(k, DataPrefix) {
continue
}
2017-03-16 16:44:58 +08:00
key := k[len(DataPrefix):]
2017-03-16 16:44:58 +08:00
DataArray = DataArray + "['" + key + "' , " + kvmap[k] + "],\n"
}
DataArray = DataArray + "]"
2017-03-16 16:44:58 +08:00
args["DataArray"] = DataArray
return args, nil
}
func (c *PieChart) Template() string {
return TemplatePieHtml
2017-03-16 16:44:58 +08:00
}