forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding donut type chart, like a pie chart with a blank circle on the …
…center and little trick for label position (wcharczuk#111) (some way of improvement)
- Loading branch information
Showing
5 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/wcharczuk/go-chart" | ||
) | ||
|
||
func drawChart(res http.ResponseWriter, req *http.Request) { | ||
pie := chart.DonutChart{ | ||
Width: 512, | ||
Height: 512, | ||
Values: []chart.Value{ | ||
{Value: 5, Label: "Blue"}, | ||
{Value: 5, Label: "Green"}, | ||
{Value: 4, Label: "Gray"}, | ||
{Value: 4, Label: "Orange"}, | ||
{Value: 3, Label: "Deep Blue"}, | ||
{Value: 3, Label: "test"}, | ||
}, | ||
} | ||
|
||
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 drawChartRegression(res http.ResponseWriter, req *http.Request) { | ||
pie := chart.DonutChart{ | ||
Width: 512, | ||
Height: 512, | ||
Values: []chart.Value{ | ||
{Value: 5, Label: "Blue"}, | ||
{Value: 2, Label: "Two"}, | ||
{Value: 1, Label: "One"}, | ||
}, | ||
} | ||
|
||
res.Header().Set("Content-Type", chart.ContentTypeSVG) | ||
err := pie.Render(chart.SVG, res) | ||
if err != nil { | ||
fmt.Printf("Error rendering pie chart: %v\n", err) | ||
} | ||
} | ||
|
||
func main() { | ||
http.HandleFunc("/", drawChart) | ||
http.HandleFunc("/reg", drawChartRegression) | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.