65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
)
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
sbc := chart.StackedBarChart{
|
|
Background: chart.Style{
|
|
Padding: chart.Box{Top: 50, Left: 50, Right: 50, Bottom: 50},
|
|
},
|
|
XAxis: chart.Style{
|
|
Show: true,
|
|
},
|
|
YAxis: chart.Style{
|
|
Show: true,
|
|
},
|
|
Bars: []chart.StackedBar{
|
|
{
|
|
Name: "Katrina like animals that are very fat and furry.",
|
|
Values: []chart.Value{
|
|
{Value: 5, Label: "Blue"},
|
|
{Value: 5, Label: "Green"},
|
|
{Value: 4, Label: "Gray"},
|
|
{Value: 3, Label: "Orange"},
|
|
{Value: 3, Label: "Test"},
|
|
{Value: 2, Label: "??"},
|
|
{Value: 1, Label: "!!"},
|
|
},
|
|
},
|
|
{
|
|
Name: "Test",
|
|
Values: []chart.Value{
|
|
{Value: 10, Label: "Blue"},
|
|
{Value: 5, Label: "Green"},
|
|
{Value: 1, Label: "Gray"},
|
|
},
|
|
},
|
|
{
|
|
Name: "Test 2",
|
|
Values: []chart.Value{
|
|
{Value: 10, Label: "Blue"},
|
|
{Value: 6, Label: "Green"},
|
|
{Value: 4, Label: "Gray"},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
res.Header().Set("Content-Type", "image/svg+xml")
|
|
err := sbc.Render(chart.SVG, res)
|
|
if err != nil {
|
|
fmt.Printf("Error rendering chart: %v\n", err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
http.HandleFunc("/", drawChart)
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
}
|