2014-12-26 21:03:34 +08:00
|
|
|
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) {
|
2014-12-26 21:03:34 +08:00
|
|
|
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")
|
2014-12-27 15:05:01 +08:00
|
|
|
|
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]
|
|
|
|
]
|
|
|
|
*/
|
|
|
|
|
2014-12-26 21:03:34 +08:00
|
|
|
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 {
|
2014-12-26 21:03:34 +08:00
|
|
|
if !strings.HasPrefix(k, DataPrefix) {
|
|
|
|
continue
|
|
|
|
}
|
2017-03-16 16:44:58 +08:00
|
|
|
|
2014-12-26 21:03:34 +08:00
|
|
|
key := k[len(DataPrefix):]
|
2017-03-16 16:44:58 +08:00
|
|
|
DataArray = DataArray + "['" + key + "' , " + kvmap[k] + "],\n"
|
2014-12-26 21:03:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataArray = DataArray + "]"
|
2017-03-16 16:44:58 +08:00
|
|
|
|
2014-12-26 21:03:34 +08:00
|
|
|
args["DataArray"] = DataArray
|
|
|
|
return args, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PieChart) Template() string {
|
|
|
|
return TemplatePieHtml
|
2017-03-16 16:44:58 +08:00
|
|
|
}
|