Documentation
¶
Overview ¶
Package chartjs simplifies making chartjs.org plots in go.
Index ¶
Constants ¶
const ( // Line is a "line" plot Line chartType = iota // Bar is a "bar" plot Bar // Bubble is a "bubble" plot Bubble )
const ( InterpMonotone interpMode InterpDefault )
const ( Circle Triangle Rect RectRot Cross CrossRot Star LinePoint Dash )
const ( // Category is a categorical axis (this is the default), // used for bar plots. Category axisType = iota // Linear axis should be use for scatter plots. Linear // Log axis Log // Time axis Time // Radial axis Radial )
const ( // Bottom puts the axis on the bottom (used for Y-axis) Bottom axisPosition = iota + 1 // Top puts the axis on the bottom (used for Y-axis) Top // Left puts the axis on the bottom (used for X-axis) Left // Right puts the axis on the bottom (used for X-axis) Right )
Variables ¶
var ChartJS = "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.js"
ChartJS holds the path to hosted ChartJS
var False = types.False
var JQuery = "https://code.jquery.com/jquery-2.2.4.min.js"
JQuery holds the path to hosted JQuery
var True = types.True
var XFloatFormat = "%.2f"
XFloatFormat determines how many decimal places are sent in the JSON for X values.
var YFloatFormat = "%.2f"
YFloatFormat determines how many decimal places are sent in the JSON for Y values.
Functions ¶
Types ¶
type Axis ¶
type Axis struct {
Type axisType `json:"type"`
Position axisPosition `json:"position,omitempty"`
Label string `json:"label,omitempty"`
ID string `json:"id,omitempty"`
GridLines types.Bool `json:"gridLine,omitempty"`
Stacked types.Bool `json:"stacked,omitempty"`
// Bool differentiates between false and empty by use of pointer.
Display types.Bool `json:"display,omitempty"`
ScaleLabel *ScaleLabel `json:"scaleLabel,omitempty"`
Tick *Tick `json:"ticks,omitempty"`
}
Axis corresponds to 'scale' in chart.js lingo.
type Chart ¶
type Chart struct {
Type chartType `json:"type"`
Label string `json:"label,omitempty"`
Data Data `json:"data,omitempty"`
Options Options `json:"options,omitempty"`
}
Chart is the top-level type from chartjs.
func (*Chart) AddDataset ¶
AddDataset adds a dataset to the chart.
type Dataset ¶
type Dataset struct {
Data Values `json:"-"`
Type chartType `json:"type,omitempty"`
BackgroundColor *types.RGBA `json:"backgroundColor,omitempty"`
// BorderColor is the color of the line.
BorderColor *types.RGBA `json:"borderColor,omitempty"`
// BorderWidth is the width of the line.
BorderWidth float64 `json:"borderWidth"`
// Label indicates the name of the dataset to be shown in the legend.
Label string `json:"label,omitempty"`
Fill types.Bool `json:"fill,omitempty"`
// SteppedLine of true means dont interpolate and ignore line tension.
SteppedLine types.Bool `json:"steppedLine,omitempty"`
LineTension float64 `json:"lineTension"`
CubicInterpolationMode interpMode `json:"cubicInterpolationMode,omitempty"`
PointBackgroundColor *types.RGBA `json:"pointBackgroundColor,omitempty"`
PointBorderColor *types.RGBA `json:"pointBorderColor,omitempty"`
PointBorderWidth float64 `json:"pointBorderWidth"`
PointRadius float64 `json:"pointRadius"`
PointHitRadius float64 `json:"pointHitRadius"`
PointHoverRadius float64 `json:"pointHoverRadius"`
PointHoverBorderColor *types.RGBA `json:"pointHoverBorderColor,omitempty"`
PointHoverBorderWidth float64 `json:"pointHoverBorderWidth"`
PointStyle shape `json:"pointStyle,omitempty"`
ShowLine types.Bool `json:"showLine,omitempty"`
SpanGaps types.Bool `json:"spanGaps,omitempty"`
// Axis ID that matches the ID on the Axis where this dataset is to be drawn.
XAxisID string `json:"xAxisID,omitempty"`
YAxisID string `json:"yAxisID,omitempty"`
// set the formatter for the data, e.g. "%.2f"
// these are not exported in the json, just used to determine the decimals of precision to show
XFloatFormat string `json:"-"`
YFloatFormat string `json:"-"`
}
Dataset wraps the "dataset" JSON
func (Dataset) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface.
type Option ¶
type Option struct {
Responsive types.Bool `json:"responsive,omitempty"`
MaintainAspectRatio types.Bool `json:"maintainAspectRatio,omitempty"`
Title *Title `json:"title,omitempty"`
}
Option wraps the chartjs "option"
type Options ¶
type Options struct {
Option
Scales Axes `json:"scales,omitempty"`
Legend *Legend `json:"legend,omitempty"`
Tooltip *Tooltip `json:"tooltips,omitempty"`
}
Options wraps the chartjs "options"
type ScaleLabel ¶
type ScaleLabel struct {
Display types.Bool `json:"display,omitempty"`
LabelString string `json:"labelString,omitempty"`
FontColor *types.RGBA `json:"fontColor,omitempty"`
FontFamily string `json:"fontFamily,omitempty"`
FontSize int `json:"fontSize,omitempty"`
FontStyle string `json:"fontStyle,omitempty"`
}
ScaleLabel corresponds to scale title. Display: True must be specified for this to be shown.
type Tick ¶
type Tick struct {
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
BeginAtZero types.Bool `json:"beginAtZero,omitempty"`
}
Tick lets us set the range of the data.
type Title ¶
type Title struct {
Display types.Bool `json:"display,omitempty"`
Text string `json:"text,omitempty"`
}
Title is the Options title
type Tooltip ¶
type Tooltip struct {
Enabled types.Bool `json:"enabled,omitempty"`
Intersect types.Bool `json:"intersect,omitempty"`
// TODO: make mode typed by Interaction modes.
Mode string `json:"mode,omitempty"`
Custom template.JSStr `json:"custom,omitempty"`
}
Tooltip wraps chartjs "tooltips". TODO: figure out how to make this work.

