Documentation
¶
Overview ¶
Package piechart implements a pie chart plotter for package gonum.org/v1/plot.
Pies rendering is fully customizable (see below). In particular, multiple pies can be combined on one chart, thanks to the Offset and Total attributes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PieChart ¶
type PieChart struct { plotter.Values // Radius is the radius of the pie with respect to // the chart size. If 0, the pie is a simple dot, if 1, it fills the chart // (given that the axes range from -1 to 1). // Default: 0.8 Radius float64 // Color is the fill color of the pie slices. Color color.Color // LineStyle is the style of the outline of the pie slices. // In particular, LineStyle.Width may be set to change the spacing // between slices (defaults to vg.Length(2)). draw.LineStyle Offset struct { // Value is the value added to the position of each slice in the pie, // as if there was an invisible slice with value Value before. // When this Value offset is zero (default), the slices are drawn one after // the other, counter-clockwise, starting from the right side. Value float64 // X is the length added to the X position of the pie. // When the X offset is zero, the pie is centered horizontally. X vg.Length // Y is the length added to the Y position the pie. // When the Y offset is zero, the pie is centered vertically. Y vg.Length } // Total is the total of values required to fill the pie, it defaults to // the sum of all Values. // If changed to be greater than this sum, the slices will not fill the pie. // If less, it will be reset to the default and fill the pie (slices // can not overlay each other). Total float64 Labels struct { // Show (default: true) is used to determine whether labels should be // displayed in each slice of the pie chart Show bool // Position is the location of the label: // 0 is for the center of the pie; // 1 is for the side of the slice. // A value greater than 1 is outside of the pie (default: 0.8) Position float64 // TextStyle is the style of the slices label text. draw.TextStyle // Nominal can be used to override the displayed labels (if not used, // regular indexes are displayed). // Useful in particular in combination with Offset.Value, to offset // manually the displayed indexes. Nominal []string Values struct { // Show (default: false) sets whether values should be displayed // along with indexes. Show bool // Percentage (default: false) is to display the percent value // of each slice instead of the real value. // The percentage is computed with respect to the given Total // value (if any). Percentage bool } } // contains filtered or unexported fields }
PieChart presents data values as slices in a pie, with area proportional to the data values.
func NewPieChart ¶
NewPieChart returns a new pie chart with a single slice for each value. The slice areas correspond to the values.
Since this chart is not related to axes, this should probably be used in conjunction with p.HideAxes().
func (*PieChart) DataRange ¶
DataRange implements the https://godoc.org/gonum.org/v1/plot#DataRanger interface.
A pie chart is always defined in the range (-1, -1) to (1, 1). If something different is required, change the Offset.X/Y or Radius attributes of the PieChart to move or resize it.
func (*PieChart) Plot ¶
Plot implements the https://godoc.org/gonum.org/v1/plot#Plotter interface.