pie charts!
This commit is contained in:
parent
ec4d92fc5e
commit
c17c9a4bb4
10 changed files with 485 additions and 45 deletions
35
examples/pie_chart/main.go
Normal file
35
examples/pie_chart/main.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
pie := chart.PieChart{
|
||||
Canvas: chart.Style{
|
||||
FillColor: chart.ColorLightGray,
|
||||
},
|
||||
Values: []chart.PieChartValue{
|
||||
{Value: 0.3, Label: "Blue"},
|
||||
{Value: 0.2, Label: "Green"},
|
||||
{Value: 0.2, Label: "Gray"},
|
||||
{Value: 0.1, Label: "Orange"},
|
||||
{Value: 0.1, Label: "??"},
|
||||
},
|
||||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
err := pie.Render(chart.PNG, res)
|
||||
if err != nil {
|
||||
fmt.Printf("Error rendering pie chart: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", drawChart)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue