This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stacked bar chart value labels (#60) and a horizontal stacked bar…
… chart (#39) (#114) * Add stacked bar chart value labels (#60) * Add horizontal render option to stacked bar chart (#39) * Pulling 100% inside the canvasBox to remain visible. * Use correct margins for YAxis.TextHorizontalAlign: chart.TextHorizontalAlignRight * Fixed Show to Hidden due to 5f42a58
- Loading branch information
Showing
7 changed files
with
688 additions
and
8 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,222 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/wcharczuk/go-chart" | ||
"github.com/wcharczuk/go-chart/drawing" | ||
) | ||
|
||
func main() { | ||
chart.DefaultBackgroundColor = chart.ColorTransparent | ||
chart.DefaultCanvasColor = chart.ColorTransparent | ||
|
||
barWidth := 80 | ||
|
||
var ( | ||
colorWhite = drawing.Color{R: 241, G: 241, B: 241, A: 255} | ||
colorMariner = drawing.Color{R: 60, G: 100, B: 148, A: 255} | ||
colorLightSteelBlue = drawing.Color{R: 182, G: 195, B: 220, A: 255} | ||
colorPoloBlue = drawing.Color{R: 126, G: 155, B: 200, A: 255} | ||
colorSteelBlue = drawing.Color{R: 73, G: 120, B: 177, A: 255} | ||
) | ||
|
||
stackedBarChart := chart.StackedBarChart{ | ||
Title: "Quarterly Sales", | ||
TitleStyle: chart.StyleShow(), | ||
Background: chart.Style{ | ||
Padding: chart.Box{ | ||
Top: 75, | ||
}, | ||
}, | ||
Width: 800, | ||
Height: 600, | ||
XAxis: chart.StyleShow(), | ||
YAxis: chart.StyleShow(), | ||
BarSpacing: 40, | ||
IsHorizontal: true, | ||
Bars: []chart.StackedBar{ | ||
{ | ||
Name: "Q1", | ||
Width: barWidth, | ||
Values: []chart.Value{ | ||
{ | ||
Label: "32K", | ||
Value: 32, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorMariner, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "46K", | ||
Value: 46, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorLightSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "48K", | ||
Value: 48, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorPoloBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "42K", | ||
Value: 42, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Q2", | ||
Width: barWidth, | ||
Values: []chart.Value{ | ||
{ | ||
Label: "45K", | ||
Value: 45, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorMariner, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "60K", | ||
Value: 60, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorLightSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "62K", | ||
Value: 62, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorPoloBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "53K", | ||
Value: 53, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Q3", | ||
Width: barWidth, | ||
Values: []chart.Value{ | ||
{ | ||
Label: "54K", | ||
Value: 54, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorMariner, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "58K", | ||
Value: 58, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorLightSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "55K", | ||
Value: 55, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorPoloBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "47K", | ||
Value: 47, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Q4", | ||
Width: barWidth, | ||
Values: []chart.Value{ | ||
{ | ||
Label: "46K", | ||
Value: 46, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorMariner, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "70K", | ||
Value: 70, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorLightSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "74K", | ||
Value: 74, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorPoloBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
{ | ||
Label: "60K", | ||
Value: 60, | ||
Style: chart.Style{ | ||
StrokeWidth: .01, | ||
FillColor: colorSteelBlue, | ||
FontColor: colorWhite, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
pngFile, err := os.Create("output.png") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := stackedBarChart.Render(chart.PNG, pngFile); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := pngFile.Close(); err != nil { | ||
panic(err) | ||
} | ||
} |
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.