Our library focuses on generating beautiful charts and graphs within Go. Graphs are used to show a lot of different types of data, needing to be represented in a unique in order to convey the meaning behind the data. This Go module attempts to use sophisticated defaults to try and render this data in a simple way, while still offering intuitive options to update the graph rendering as you see fit.
Currently supported chart types: line
, scatter
, bar
, horizontal bar
, pie
, radar
, funnel
and table
.
New users should check out the Features Overview on our Wiki to see commonly used features for each chart type, as well as linking to specific examples for the feature.
We also have an extensive catalog of examples. Reference the README within the examples
directory to see a list of our example implementations of each chart type and configurations.
Our library offers a wide range of themes, the examples below are only a small subset of what we offer. See our Themes list in Feature Overview to see our complete theme list.
Line Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#line-charts
import (
"github.com/go-analyze/charts"
)
func main() {
// values specified where the first index is for each data series or source, and the second index is for each sample.
values := [][]float64{
{ // Email
120, // Mon
132, // Tue
101, // Wed
134, // Thu
90, // Fri
230, // Sat
210, // Sun
},
{
// values for 'Search Engine' go here
},
}
opt := charts.NewLineChartOptionWithData(values)
opt.Title = charts.TitleOption{
Text: "Line Chart Demo",
}
opt.XAxis.Labels = []string{
// The 7 labels here match to the 7 values above
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
}
opt.Legend = charts.LegendOption{
SeriesNames: []string{
"Email", "Search Engine",
},
}
// other options as desired...
p := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 400,
})
err := p.LineChart(opt)
// ... err check
buf, err := p.Bytes()
// ...
Top Line Chart Examples:
- line_chart-1-basic - Basic line chart with some simple styling changes and a demonstration of
null
values. - line_chart-2-symbols - Basic line chart which sets a different symbol for each series item.
- line_chart-3-smooth - Basic line chart with thick smooth lines drawn.
- line_chart-4-mark - Line chart with included mark points and mark lines.
- line_chart-6-stacked - Line chart with "Stacked" series enabled, making each series a layer on the chart and the top line showing the sum.
- line_chart-8-dual_y_axis - Basic line chart with two series, one rendered to the left axis and one to a second y axis on the right.
Scatter Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#scatter-charts
import (
"github.com/go-analyze/charts"
)
func main() {
opt := charts.NewScatterChartOptionWithData([][]float64{
{120, 132, 101, charts.GetNullValue(), 90, 230, 210},
{ /* values for search engine go here */ },
})
opt.Title.Text = "Scatter"
opt.XAxis.Labels = []string{
// The 7 labels here match to the 7 values above
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
}
opt.Legend.SeriesNames = []string{"Email", "Search Engine"}
// set other field options as desired...
p := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 400,
})
err := p.ScatterChart(opt)
// ... err check
buf, err := p.Bytes()
// ...
Top Scatter Chart Examples:
- scatter_chart-1-basic - Basic scatter chart with some simple styling changes and a demonstration of
null
values. - scatter_chart-3-dense_data - Scatter chart with dense data, trend lines, and more custom styling configured.
Bar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#bar-charts
import (
"github.com/go-analyze/charts"
)
func main() {
// values specified where the first index is for each data series or source, and the second index is for each sample.
values := [][]float64{
{ // Rainfall data
2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3,
},
{
// 'Evaporation' data goes here
},
}
opt := charts.NewBarChartOptionWithData(values)
opt.XAxis.Labels = []string{
// A label for each position in the values above
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
}
opt.Legend = charts.LegendOption{
SeriesNames: []string{
"Rainfall", "Evaporation",
},
Offset: charts.OffsetRight,
}
// Example of adding a mark line across the bars, or mark points for specific values
opt.SeriesList[0].MarkLine.AddLines(charts.SeriesMarkTypeAverage)
opt.SeriesList[0].MarkPoint.AddPoints(charts.SeriesMarkTypeMax, charts.SeriesMarkTypeMin)
// other options as desired...
p := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 400,
})
err := p.BarChart(opt)
// ... err check
buf, err := p.Bytes()
// ...
Top Bar Chart Examples:
- bar_chart-1-basic - Basic bar chart.
- bar_chart-4-mark - Bar chart with included mark points and mark lines.
Horizontal Bar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#horizontal-bar-charts
Top Horizontal Bar Chart Examples:
- horizontal_bar_chart-1-basic - Basic horizontal bar chart.
Pie Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#pie-charts
import (
"github.com/go-analyze/charts"
)
func main() {
values := []float64{
1048, // Search Engine
735, // Direct
580, // Email
484, // Union Ads
300, // Video Ads
}
opt := charts.NewPieChartOptionWithData(values)
opt.Title = charts.TitleOption{
Text: "Pie Chart",
Offset: charts.OffsetCenter,
}
opt.Legend.SeriesNames = []string{
"Search Engine", "Direct", "Email", "Union Ads", "Video Ads",
}
// other options as desired...
p := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 400,
})
err := p.PieChart(opt)
// ... err check
buf, err := p.Bytes()
// ...
Top Pie Chart Examples:
- pie_chart-1-basic - Pie chart with a variety of customization demonstrated including positioning the legend in the bottom right corner.
- pie_chart-2-radius - Pie chart which varies the series radius by the percentage of the series.
Radar Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#radar-charts
Top Radar Chart Examples:
- radar_chart-1-basic - Basic radar chart.
Table Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#tables
Top Table Examples:
- table-1 - Table with a variety of table specific configuration and styling demonstrated.
Funnel Chart Feature List: https://github.com/go-analyze/charts/wiki/Feature-Overview#funnel-charts
import (
"github.com/go-analyze/charts"
)
func main() {
values := []float64{
100, // Show
80, // Click
60, // Visit
40, // Inquiry
20, // Order
}
opt := charts.NewFunnelChartOptionWithData(values)
opt.Title.Text = "Funnel Chart"
opt.Legend.SeriesNames = []string{
"Show", "Click", "Visit", "Inquiry", "Order",
}
p := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 400,
})
err := p.FunnelChart(opt)
// ... err check
buf, err := p.Bytes()
Top Funnel Chart Examples:
- funnel_chart-1-basic - Basic funnel chart.
import (
"github.com/go-analyze/charts"
)
func main() {
buf, err := charts.RenderEChartsToPNG(`{
"title": {
"text": "Line Chart"
},
"xAxis": {
"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
},
"series": [
{
"data": [150, 230, 224, 218, 135, 147, 260]
}
]
}`)
// snip...
Forked from vicanso/go-charts and the archived wcharczuk/go-chart, our project introduces enhancements for rendering challenging datasets. We aim to build upon their solid foundation to offer a more versatile and user-friendly charting solution.
We're committed to refining the API, incorporating feedback and new ideas to enhance flexibility and ease of use.
Until the v1.0.0
release, API changes should be anticipated. We detail needed API changes on our wiki Version Migration Guide.
Notable improvements in our fork include:
- Expanded Features: We continue to develop and extend this library. Recent additions include scatter charts with trend lines, a wide range of built-in themes, stacked series, improved support for eCharts configurations, and smooth line rendering.
- Intuitive Configuration: Our goal is to ensure configuration options are clear and easy to use. In addition to refining the Go API, we have expanded our documentation in both GoDocs and the Wiki.
- Expanded Testing: We are committed to comprehensive test coverage. Increased test coverage has led to significant bug fixes, ensuring better reliability across a wide range of configurations.
Our library is an evolving project, aiming to become a standout choice for Go developers seeking powerful yet easy-to-use charting tools. We welcome contributions and feedback as we continue to enhance our library's functionality, configurability, and reliability.
If you're migrating from wcharczuk/go-chart
, you should be able to migrate with minimal modifications. The wcharczuk/go-chart
codebase has been integrated into our chartdraw
package. Any necessary changes are documented in our wcharczuk/go‐chart Migration Guide.