-
Notifications
You must be signed in to change notification settings - Fork 6
vicanso go‐charts Migration Guide
This guide explains how to migrate from the archived vicanso/go-charts
to go-analyze/charts
. Subsequent updates are documented in the go-analyze/charts
Version Migration Guide.
We forked vicanso/go-charts
to enhance the flexibility and readability of the charts for a wider range of data sets. Initially, we focused on improving x-axis rendering. Since then, we have expanded unit test coverage, which has helped us find and fix numerous bugs, especially for unusual datasets.
We are committed to exploring new use cases and make rendering beautiful graphs in Go easy and intuitive.
Below are the key changes for migrating your code. They are grouped by configuration area to help you find where your code needs changes. If you need deeper technical details, check the corresponding pull request (PR) or open an issue if you’re still unsure.
Old Name | New Name | PR | Notes |
---|---|---|---|
Type (in ChartOption) |
OutputFormat |
#5 | Output format for charts (e.g. "png" , "svg" ) |
SVGTypeOption() |
SVGOutputOptionFunc() |
#27 | Renamed for consistency |
PNGTypeOption() |
PNGOutputOptionFunc() |
#27 | Renamed for consistency |
TypeOptionFunc |
SVGOutputOptionFunc() , PNGOutputOptionFunc()
|
#27 | Removed in favor of specific types |
TrueFlag() , FalseFlag()
|
Ptr(true) / Ptr(false)
|
#44 | Replaced with generic pointer helper functions |
NewFloatPoint(float64) |
Ptr(float64) |
#44 | New name for float-pointer constructor using generics |
YAxisOptions (field/struct) |
YAxis |
#5 | Removes “Options” suffix for consistency |
FirstAxis |
DataStartIndex |
#5 | Indicates zero-based index for axis Data
|
SplitNumber |
Removed | #3 | Replaced by new label config (Unit , LabelCount , etc.) |
StrokeColor , SplitLineColor
|
Removed | #5 | Use theme or WithAxisColor(...) for custom axis color |
Opacity (Line charts) |
FillOpacity |
#5 | Clarifies that opacity is for the fill area |
Padding (in Table) |
CellPadding |
#5 | Avoids confusion with chart-level padding |
Orient (Title/Legend) |
Vertical (*bool) |
#20 |
OrientationHorizontal / OrientationVertical removed |
Title.Top / Title.Left
|
Title.Offset.Top / Offset.Left
|
#20 | For clearer offset usage. Similar for Legend.Top /Left
|
Box offsets for labels |
OffsetInt |
#9 | Struct with only Top and Left is more intuitive |
WidthOptionFunc , HeightOptionFunc
|
DimensionsOptionFunc |
#27 | Dimensions now set together |
SetDefaultWidth , SetDefaultHeight
|
SetDefaultChartDimensions |
#27 | Dimensions now set together |
Painter.ArrowTop |
Painter.ArrowUp |
#27 | Renamed for clarity |
Painter.ArrowBottom |
Painter.ArrowDown |
#27 | Renamed for clarity |
LineChartOption.StrokeWidth |
LineStrokeWidth |
#27 | Renamed for consistency |
LineChartOption.SymbolShow |
LineChartOption.Symbol |
#44 | Now accepts multiple symbol types, use SymbolNone to disable symbols |
XAxisOption.TextRotation |
XAxisOption.LabelRotation |
#44 | Clarifies the labels are being rotated |
LegendOption.Icon |
LegendOption.Symbol |
#44 | Consistent naming with LineChartOption |
LegendOption.Data |
LegendOption.SeriesNames |
#44 | To clarify this correlates to the names of the series |
XAxisOption.Data |
XAxisOption.Labels |
#44 | Clarifies that this represents axis labels rather than series data |
YAxisOption.Data |
YAxisOption.Labels |
#44 | Clarifies that this represents axis labels rather than series data |
XAxisDataOptionFunc |
XAxisLabelsOptionFunc |
#44 | Updated to reflect new field name |
YAxisDataOptionFunc |
YAxisLabelsOptionFunc |
#44 | Updated to reflect new field name |
-
Type
→OutputFormat
- Clarifies that the field sets the output format (e.g.,
"png"
,"svg"
). (see PR #5)
- Clarifies that the field sets the output format (e.g.,
-
TypeOptionFunc
has been replaced bySVGOutputOptionFunc()
andPNGOutputOptionFunc()
for clarity. (see PR #27)
-
Option Helper Functions Replaced with
charts.Ptr
- More concise API, and allows better struct construction readability (see PR #44).
-
TrueFlag()
,FalseFlag()
,BoolPointer(bool)
, andFloatPointer(float64)
replaced with the genericcharts.Ptr()
. - Example:
NewFloatPointer(1.5)
→Ptr(1.5)
-
“Option” Suffix Removed from Field Names
- Fields and types ending in
Options
orOption
have been renamed. For example,YAxisOptions
is nowYAxis
. (see PR #5)
- Fields and types ending in
-
Fonts and Themes Removed From Global Registry
- Themes and Fonts are now set directly on the chart configuration instead of being looked up from a global registry. You can still load built-in themes by name (e.g.,
GetTheme(...)
), but it is no longer required. (see PR #4) - Many color fields were removed in favor of themes. For specific overrides, use theme modifiers like
WithAxisColor(...)
.
- Themes and Fonts are now set directly on the chart configuration instead of being looked up from a global registry. You can still load built-in themes by name (e.g.,
-
Font Configuration with
FontStyle
- Instead of separate top-level properties like
FontSize
andFontColor
, each component (title, legend, axis) now has aFontStyle
struct to configure font properties.
- Instead of separate top-level properties like
-
Dimensions Now Set Together
-
WidthOptionFunc
andHeightOptionFunc
are now consolidated intoDimensionsOptionFunc
. Similarly,SetDefaultWidth
andSetDefaultHeight
are replaced bySetDefaultChartDimensions
. (see PR #27)
-
-
YAxisOptions
→YAxis
- Reflects the removal of “Options” suffix (see PR #5).
-
Field Renaming
-
Data
→Labels
- Clarifies that this field represents axis labels, not series data (see PR #44). -
FirstAxis
→DataStartIndex
- To clarify it is the zero-based index from whichLabels
should begin (see PR #5). -
TextRotation
→LabelRotation
- To clarify that the axis labels are being rotated (see PR #44).
-
-
FirstAxis
→DataStartIndex
- Clarifies that it’s the zero-based index from which your
Data
should begin (see PR #5).
- Clarifies that it’s the zero-based index from which your
-
Removed Color Fields
-
Axis Label Configuration (see PR #3)
-
Unit
: Suggests the increment for axis labels. The minimum and maximum values are always shown. -
LabelCount
: Sets the exact number of labels to render, overridingUnit
if both are set. -
LabelCountAdjustment
: Relative tweak to the auto-determined label count (negative yields fewer labels, positive yields more). -
LabelSkipCount
: Skips rendering every Nth label. -
RangeValuePaddingScale
: Suggests extra padding for the y-axis range. No padding is added ifMin
orMax
are set explicitly (unless needed to satisfyUnit
). -
SplitNumber
: REMOVED. Use the properties described above instead.
-
-
Field Renaming
-
Icon
→Symbol
- For consistency withLineChartOption
; now accepts more symbol types. -
Data
→SeriesNames
- To clarify this correlates to the names of the series.
-
-
Title & Legend (see PR #20)
-
Title.Top
/Title.Left
→Title.Offset.Top
/Title.Offset.Left
. -
Legend.Top
/Legend.Left
→Legend.Offset.Top
/Legend.Offset.Left
. -
Orient
(horizontal/vertical) is replaced by a simpleVertical
bool. - The previous
PositionLeft
,PositionCenter
, andPositionRight
are nowOffsetLeft
,OffsetCenter
, andOffsetRight
.
-
-
LabelOffset
-
LabelOffset
was aBox
that only respectedTop
andLeft
. Now it’s a more intuitiveOffsetInt
struct, reflecting only the fields actually used (Top
,Left
) (see PR #9).
-
-
Horizontal Legend Without Title Behavior (see PR #25)
- When a legend is present without a title,
vicanso/go‐charts
would overlap the legend with the chart data. We now space the chart below the legend. To restore the old behavior, setLegendOption.OverlayChart
to*true
.
-
SeriesList
construction is now type-specific.NewSeriesListDataFromValues
andNewSeriesFromValues
have been removed. Use type-specific constructors likeNewSeriesListX
instead (whereX
is the chart type). ThoughOptions
structs can be more easily created with helpers likeNewXChartOptionWithData
, reducing the need for manualSeriesList
construction. -
The
SeriesData
struct has been removed.Series
values are now stored directly as afloat64
slice. -
Chart-Specific Series Types
- The
SeriesList
type is now specific to each chart type (see PR #44):-
ChartOption
→GenericSeriesList
-
LineChartOption
→LineSeriesList
-
BarChartOption
→BarSeriesList
-
HorizontalBarChartOption
→HorizontalBarSeriesList
-
FunnelChartOption
→FunnelSeriesList
-
PieChartOption
→PieSeriesList
-
RadarChartOption
→RadarSeriesList
-
- Fields have been renamed for consistency:
-
Data
→Values
(orValue
for single-value charts like Pie and Funnel)
-
- Example:
NewSeriesListLine
replaces previous generic series list creation (see PR #45).
- The
-
Series Labeling
-
Formatter
→ replaced withFormatTemplate
-
Position
→ moved to chart Options struct asSeriesLabelPosition
for bar and horizontal bar charts
-
The Painter
is now more flexible. You can create one with NewPainter
, build chart configuration structs, and render them to the Painter
. Public functions are available to add annotations like text, lines, arrows and additional elements to your charts.
-
The
Renderer
type and itsNew*
constructor functions have been removed. To render charts, call the corresponding methods on aPainter
instance:-
NewBarChart
->Painter.BarChart
-
NewHorizontalBarChart
->Painter.HorizontalBarChart
-
NewFunnelChart
->Painter.FunnelChart
-
NewLineChart
->Painter.LineChart
-
NewPieChart
->Painter.PieChart
-
NewRadarChart
->Painter.RadarChart
-
NewTableChart
->Painter.TableChart
-
-
The
Painter
is no longer stateful. Style attributes (e.g., fill color, stroke width) are now passed as arguments to its functions. ThePainter
API has been revised to be more user-friendly. -
ValueFormatter
has been removed from thePainter
configuration. It should now be specified on the chartOptions
struct or other relevant configurations, allowing for more precise format control.
- The functions
NewLegendOption
,NewXAxisOption
, andNewYAxisOptions
have been removed (see PR #20). Structs are now created directly:// Old opt.XAxis = NewXAxisOption(data, charts.True()) // New opt.XAxis = XAxis{ Labels: data, BoundaryGap: charts.Ptr(true), }
The exception to this is the chart specific configs, which can be constructed using NewBarChartOptionWithData
, NewHorizontalBarChartOptionWithData
, NewLineChartOptionWithData
, etc.
-
Line Charts
-
Opacity
is nowFillOpacity
to clarify that it applies to the fill area. -
FillArea
is now a boolean pointer, set usingcharts.Ptr(true)
. -
ShowSymbol
is replaced withSymbol
, accepting multiple symbol types. To hide symbols, useSymbolNone
.
-
-
Table Charts
-
Padding
is nowCellPadding
to avoid confusion with chart-level padding. - A
CellModifier
callback can now be used to override cell styles before rendering. -
TableChartOption
now uses aFontStyle
struct for text styling, replacing top-level properties likeFontSize
andFontColor
.
-
-
Bar Charts
-
YAxisOptions
replaced withYAxis
.
-
-
Horizontal Bar Charts
-
YAxis
is now a single struct instead of a slice.
-
To make the API easier to understand, we have made many functions and structs internal (see PR #27).
If you rely on functionality that is no longer public or need help migrating, please open an issue. We watch issues closely and welcome your feedback.