### InstallFont Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of how to install a custom font. ```go fontData, _ := ioutil.ReadFile("Arial.ttf") err := charts.InstallFont("Arial", fontData) if err != nil { return err } ``` -------------------------------- ### Style Configuration Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of how to configure Style fields. ```go style := charts.Style{ FontSize: 12, FontColor: charts.Color{R: 0, G: 0, B: 0, A: 255}, StrokeColor: charts.Color{R: 200, G: 0, B: 0, A: 255}, StrokeWidth: 2, } ``` -------------------------------- ### NewTheme Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of creating a new theme. ```go theme := charts.NewTheme(charts.ThemeDark) ``` -------------------------------- ### Custom Font Configuration Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Shows how to install a custom font and then use it in a chart. ```go // Install custom font fontData, _ := ioutil.ReadFile("myfont.ttf") charts.InstallFont("MyFont", fontData) // Use in chart p, err := charts.LineRender( values, charts.FontFamilyOptionFunc("MyFont"), ) ``` -------------------------------- ### SetDefaultFont Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of how to set the default font. ```go font, _ := charts.GetFont("Arial") charts.SetDefaultFont(font) ``` -------------------------------- ### GetDefaultFont Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of how to get the default font. ```go font, _ := charts.GetDefaultFont() ``` -------------------------------- ### Theme Application Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example demonstrating full theme control at the chart level. ```go p, err := charts.LineRender( values, charts.ThemeOptionFunc(charts.ThemeDark), charts.TitleOptionFunc(charts.TitleOption{ Text: "Sales", Theme: nil, // Use chart theme }), ) ``` -------------------------------- ### GetFont Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of how to retrieve a registered font. ```go font, err := charts.GetFont("Arial") if err != nil { return err } ``` -------------------------------- ### ThemeGrafana Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of using the Grafana theme. ```go charts.ThemeOptionFunc(charts.ThemeGrafana) ``` -------------------------------- ### X-Axis Basic Setup Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Demonstrates the basic setup for an X-axis, typically used for categorical data. ```go xAxis := charts.NewXAxisOption([]string{ "Jan", "Feb", "Mar", "Apr", "May", }) p, _ := charts.LineRender(values, charts.XAxisOptionFunc(xAxis)) ``` -------------------------------- ### ValueFormatter Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/03-types-and-structures.md An example demonstrating how to create a ValueFormatter function to format numbers as percentages with two decimal places. ```go formatter := func(v float64) string { return fmt.Sprintf("%.2f%%", v) } ``` -------------------------------- ### ThemeAnt Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of using the Ant Design theme. ```go charts.ThemeOptionFunc(charts.ThemeAnt) ``` -------------------------------- ### ThemeDark Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Example of using the dark theme. ```go charts.ThemeOptionFunc(charts.ThemeDark) ``` -------------------------------- ### Testing Pattern Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md An example of how to test chart rendering functionality using Go's built-in testing package. ```go func TestChartRendering(t *testing.T) { values := [][]float64{{10, 20, 30}} p, err := charts.LineRender(values) if err != nil { t.Errorf("Render failed: %v", err) } data, err := p.Bytes() if err != nil { t.Errorf("Export failed: %v", err) } if len(data) == 0 { t.Error("No data generated") } } ``` -------------------------------- ### Line Chart with Full Configuration Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a line chart with extensive configuration options. ```go p, err := charts.LineRender( values, charts.TitleTextOptionFunc("Monthly Sales", "2024"), charts.XAxisDataOptionFunc([]string{"Jan", "Feb", "Mar", "Apr", "May"}), charts.YAxisOptionFunc(charts.YAxisOption{ Min: TrueValue(0), Max: TrueValue(1000), }), charts.LegendLabelsOptionFunc([]string{"Product A", "Product B"}, charts.PositionRight), charts.WidthOptionFunc(1000), charts.HeightOptionFunc(600), charts.ThemeOptionFunc(charts.ThemeDark), charts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage), charts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax), ) ``` -------------------------------- ### Basic Legend Setup Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Initializing a legend with series names and position. ```go legend := charts.NewLegendOption( []string{"Series 1", "Series 2"}, charts.PositionRight, ) p, _ := charts.LineRender(values, charts.LegendOptionFunc(legend)) ``` -------------------------------- ### Render Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/01-chart-render-functions.md Example usage of the generic Render function with ChartOption and additional options. ```go opt := charts.ChartOption{ Type: charts.ChartOutputPNG, Width: 800, Height: 600, SeriesList: seriesList, Theme: "dark", } p, err := charts.Render(opt, charts.TitleTextOptionFunc("My Chart")) ``` -------------------------------- ### Simple Table Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a simple table with a header and data rows. ```go header := []string{"Name", "Age", "City"} data := [][]string{ {"Alice", "28", "New York"}, {"Bob", "35", "San Francisco"}, {"Charlie", "42", "Boston"}, } p, err := charts.TableRender(header, data) ``` -------------------------------- ### Minimal Line Chart Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a basic line chart with minimal configuration. ```go package main import ( "io/ioutil" "log" charts "github.com/vicanso/go-charts/v2" ) func main() { values := [][]float64{ {120, 132, 101, 134, 90}, } p, err := charts.LineRender(values) if err != nil { log.Fatal(err) } data, _ := p.Bytes() ioutil.WriteFile("chart.png", data, 0644) } ``` -------------------------------- ### ErrFontNotExists Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/00-overview-and-index.md Example of how to handle the ErrFontNotExists error when retrieving a font. ```go font, err := charts.GetFont("MissingFont") if err == charts.ErrFontNotExists { // Handle missing font } ``` -------------------------------- ### Pie Chart Example Source: https://github.com/vicanso/go-charts/blob/main/README.md Demonstrates the creation of a pie chart with options for title, padding, legend, and showing data labels. ```go package main import ( "github.com/vicanso/go-charts/v2" ) func main() { values := []float64{ 1048, 735, 580, 484, 300, } p, err := charts.PieRender( values, charts.TitleOptionFunc(charts.TitleOption{ Text: "Rainfall vs Evaporation", Subtext: "Fake Data", Left: charts.PositionCenter, }), charts.PaddingOptionFunc(charts.Box{ Top: 20, Right: 20, Bottom: 20, Left: 20, }), charts.LegendOptionFunc(charts.LegendOption{ Orient: charts.OrientVertical, Data: []string{ "Search Engine", "Direct", "Email", "Union Ads", "Video Ads", }, Left: charts.PositionLeft, }), charts.PieSeriesShowLabel(), ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } // snip... } ``` -------------------------------- ### Simple Pie Chart Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a simple pie chart with labels and data. ```go values := []float64{1048, 735, 580, 484, 300} p, err := charts.PieRender( values, charts.TitleTextOptionFunc("Market Share"), charts.LegendLabelsOptionFunc([]string{ "Product A", "Product B", "Product C", "Product D", "Other", }), charts.PieSeriesShowLabel(), ) ``` -------------------------------- ### HTTP Handler Pattern Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md An example of how to use go-charts within an HTTP handler to generate charts dynamically based on request parameters. ```go func chartHandler(w http.ResponseWriter, r *http.Request) { chartType := r.URL.Query().Get("type") // "line", "bar", etc. values := [][]float64{ {100, 200, 150, 300}, } var p *charts.Painter var err error switch chartType { case "bar": p, err = charts.BarRender(values) case "pie": p, err = charts.PieRender(values[0]) default: p, err = charts.LineRender(values) } if err != nil { http.Error(w, "Render failed", 500) return } data, _ := p.Bytes() w.Header().Set("Content-Type", "image/png") w.Write(data) } ``` -------------------------------- ### Quick Start Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/00-overview-and-index.md This code snippet demonstrates how to quickly generate a line chart using go-charts, set its title, X-axis data, and legend labels, and then export it to a PNG file. ```go package main import ( "io/ioutil" "log" charts "github.com/vicanso/go-charts/v2" ) func main() { // Data: 2 series with 5 values each values := [][]float64{ {10, 20, 30, 40, 50}, {15, 25, 35, 45, 55}, } // Render with title and legend p, err := charts.LineRender( values, charts.TitleTextOptionFunc("Sales"), charts.XAxisDataOptionFunc([]string{"A", "B", "C", "D", "E"}), charts.LegendLabelsOptionFunc([]string{"Q1", "Q2"}), ) if err != nil { log.Fatal(err) } // Export to PNG bytes data, _ := p.Bytes() ioutil.WriteFile("chart.png", data, 0644) } ``` -------------------------------- ### TableRender Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/01-chart-render-functions.md Example usage of the TableRender function to create a table with headers, data, and column spans. ```go header := []string{"Name", "Age", "Address", "Tag"} data := [][]string{ {"John Brown", "32", "New York No. 1", "nice, dev"}, {"Jim Green", "42", "London No. 1", "wow"}, {"Joe Black", "32", "Sidney No. 1", "cool, teacher"}, } spans := map[int]int{ 0: 2, // First column spans 2 columns 1: 1, 2: 3, 3: 2, } p, err := charts.TableRender(header, data, spans) ``` -------------------------------- ### Color Parsing Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Internal function to parse color from hex strings. ```go // Used internally, accessible through Color type color := charts.parseColor("#FF0000") // Red color := charts.parseColor("#00FF00") // Green ``` -------------------------------- ### Bar Chart with Custom Styling Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a bar chart with custom styling options. ```go opt := charts.ChartOption{ Type: charts.ChartOutputPNG, Width: 1200, Height: 600, Theme: charts.ThemeAnt, BarWidth: 30, BarMargin: 5, SeriesList: charts.NewSeriesListDataFromValues(values, charts.ChartTypeBar), XAxis: charts.NewXAxisOption(categories), Title: charts.TitleOption{ Text: "Sales by Region", Left: charts.PositionCenter, }, } p, err := charts.Render(opt) ``` -------------------------------- ### ErrFontNotExists Error Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Error returned when a requested font is not installed. ```go var ErrFontNotExists = errors.New("font is not exists") ``` ```go font, err := charts.GetFont("NonExistent") if err == charts.ErrFontNotExists { // Font not found } ``` -------------------------------- ### Sales Funnel Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a funnel chart to visualize a sales pipeline. ```go values := []float64{100, 80, 60, 40, 20} p, err := charts.FunnelRender( values, charts.TitleTextOptionFunc("Sales Pipeline"), charts.LegendLabelsOptionFunc([]string{ "Impression", "Click", "Visit", "Inquiry", "Order", }), ) ``` -------------------------------- ### TableOptionRender Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/01-chart-render-functions.md Example usage of the TableOptionRender function with a TableChartOption struct. ```go opt := charts.TableChartOption{ Header: []string{"Col1", "Col2", "Col3"}, Data: [][]string{ {"A", "B", "C"}, {"D", "E", "F"}, }, Width: 800, Type: charts.ChartOutputPNG, Theme: charts.NewTheme("dark"), } p, err := charts.TableOptionRender(opt) ``` -------------------------------- ### Set Global Defaults Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Configures global default width and height for charts, which will be used unless explicitly overridden. ```go // Set once on startup charts.SetDefaultWidth(800) charts.SetDefaultHeight(600) // All subsequent charts use these unless overridden p, _ := charts.LineRender(values) ``` -------------------------------- ### Reuse Painters Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Optimizes performance by creating a base painter once and rendering multiple charts onto it before exporting. ```go // Create base painter p, _ := charts.NewPainter(charts.PainterOptions{ Type: charts.ChartOutputPNG, Width: 1000, Height: 600, }) // Render multiple charts on it opt1.Parent = p charts.Render(opt1) opt2.Parent = p charts.Render(opt2) // Single export data, _ := p.Bytes() ``` -------------------------------- ### Table with Custom Styling Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Demonstrates how to create a table chart with custom font sizes, background colors for headers and rows, and specific cell text styling. ```go opt := charts.TableChartOption{ Type: charts.ChartOutputPNG, Width: 900, Header: header, Data: data, FontSize: 12, FontFamily: "Arial", HeaderBackgroundColor: charts.Color{R: 66, G: 135, B: 245, A: 255}, HeaderFontColor: charts.Color{R: 255, G: 255, B: 255, A: 255}, RowBackgroundColors: []charts.Color{ charts.Color{R: 245, G: 245, B: 245, A: 255}, charts.Color{R: 255, G: 255, B: 255, A: 255}, }, CellTextStyle: func(cell charts.TableCell) *charts.Style { if cell.Row == 0 { return &charts.Style{FontSize: 14} } return nil }, } p, err := charts.TableOptionRender(opt) ``` -------------------------------- ### Line Chart Example Source: https://github.com/vicanso/go-charts/blob/main/README.md Demonstrates how to create a line chart using the go-charts library. It includes options for title, X-axis data, and legend labels. ```go package main import ( charts "github.com/vicanso/go-charts/v2" ) func main() { values := [][]float64{ { 120, 132, 101, 134, 90, 230, 210, }, { // snip... }, { // snip... }, { // snip... }, { // snip... }, } p, err := charts.LineRender( values, charts.TitleTextOptionFunc("Line"), charts.XAxisDataOptionFunc([]string{ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", }), charts.LegendLabelsOptionFunc([]string{ "Email", "Union Ads", "Video Ads", "Direct", "Search Engine", }, charts.PositionCenter), ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } // snip... } ``` -------------------------------- ### Percentage Y-Axis Configuration Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of configuring a Y-axis to display percentages. ```go yAxis := charts.YAxisOption{ Min: charts.FloatPtr(0), Max: charts.FloatPtr(100), Formatter: "{value}%", } ``` -------------------------------- ### RenderEChartsToPNG Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/06-echarts-compatibility.md Example usage of the RenderEChartsToPNG function with a sample ECharts JSON. ```go jsonOptions := `{ "title": { "text": "Line Chart" }, "xAxis": { "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] }, "series": [{ "data": [150, 230, 224, 218, 135, 147, 260] }] }` data, err := charts.RenderEChartsToPNG(jsonOptions) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Performance Metrics Radar Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a radar chart to display performance metrics. ```go values := [][]float64{ {4200, 3000, 20000, 35000, 50000, 18000}, // Budget {3000, 2500, 18000, 30000, 45000, 20000}, // Actual } p, err := charts.RadarRender( values, charts.TitleTextOptionFunc("Q1 Performance"), charts.LegendLabelsOptionFunc([]string{"Budget", "Actual"}), charts.RadarIndicatorOptionFunc( []string{"Sales", "Admin", "IT", "Support", "Dev", "Marketing"}, []float64{6500, 16000, 30000, 38000, 52000, 25000}, ), ) ``` -------------------------------- ### Graceful Error Handling Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Illustrates how to handle potential errors during chart rendering and data export. ```go p, err := charts.LineRender(values, options...) if err != nil { log.Printf("Chart rendering failed: %v", err) // Return error response or default image return nil, err } data, err := p.Bytes() if err != nil { log.Printf("Chart export failed: %v", err) return nil, err } ``` -------------------------------- ### Bar Chart Example Source: https://github.com/vicanso/go-charts/blob/main/README.md Illustrates how to generate a bar chart with options for X-axis data, legend labels, and mark lines/points for average and max/min values. ```go package main import ( "github.com/vicanso/go-charts/v2" ) func main() { values := [][]float64{ { 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3, }, { // snip... }, } p, err := charts.BarRender( values, charts.XAxisDataOptionFunc([]string{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }), charts.LegendLabelsOptionFunc([]string{ "Rainfall", "Evaporation", }, charts.PositionRight), charts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage), charts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax, charts.SeriesMarkDataTypeMin), // custom option func func(opt *charts.ChartOption) { opt.SeriesList[1].MarkPoint = charts.NewMarkPoint( charts.SeriesMarkDataTypeMax, charts.SeriesMarkDataTypeMin, ) opt.SeriesList[1].MarkLine = charts.NewMarkLine( charts.SeriesMarkDataTypeAverage, ) }, ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } // snip... } ``` -------------------------------- ### FunnelRender Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/01-chart-render-functions.md Example usage of the FunnelRender function to create a funnel chart with specified data and options. ```go values := []float64{100, 80, 60, 40, 20} p, err := charts.FunnelRender( values, charts.TitleTextOptionFunc("Sales Funnel"), charts.LegendLabelsOptionFunc([]string{"Show", "Click", "Visit", "Inquiry", "Order"}), ) ``` -------------------------------- ### RadarRender Example Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/01-chart-render-functions.md Example usage of the RadarRender function to create a radar chart with specified data and options. ```go values := [][]float64{ {4200, 3000, 20000, 35000, 50000, 18000}, {2800, 2500, 18000, 30000, 45000, 20000}, } p, err := charts.RadarRender( values, charts.TitleTextOptionFunc("Performance Metrics"), charts.LegendLabelsOptionFunc([]string{"Budget", "Actual"}), charts.RadarIndicatorOptionFunc( []string{"Sales", "Admin", "IT", "Support", "Dev", "Marketing"}, []float64{6500, 16000, 30000, 38000, 52000, 25000}, ), ) ``` -------------------------------- ### Formatter for Axis Labels Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Examples of how to format axis labels with units. ```go yAxis.Formatter = "{value} %" // "10 %", "20 %", etc. yAxis.Formatter = "{value} kg" // "10 kg", "20 kg", etc. ``` -------------------------------- ### Example: Complete ECharts Option Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/06-echarts-compatibility.md A comprehensive example of an ECharts JSON configuration including title, legend, axes, and series. ```json { "type": "png", "theme": "dark", "width": 1000, "height": 600, "padding": [40, 40, 40, 40], "title": { "text": "Sales Dashboard", "subtext": "2024 Q1", "left": "center", "top": "20", "textStyle": { "fontSize": 20, "color": "#333333" } }, "legend": { "data": ["Series 1", "Series 2"], "left": "center", "top": "60", "orient": "horizontal" }, "xAxis": { "type": "category", "data": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] }, "yAxis": { "type": "value", "min": 0, "max": 1000 }, "series": [ { "name": "Series 1", "type": "line", "data": [100, 150, 200, 180, 220, 250] }, { "name": "Series 2", "type": "line", "data": [80, 120, 160, 140, 180, 200] } ] } ``` -------------------------------- ### Side-by-Side Charts Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Composes multiple charts side-by-side within a single image. ```go // Create two line charts opt1 := charts.ChartOption{ SeriesList: charts.NewSeriesListDataFromValues(values1, charts.ChartTypeLine), Width: 500, Height: 400, Box: charts.Box{Left: 0, Top: 0, Right: 500, Bottom: 400}, } opt2 := charts.ChartOption{ SeriesList: charts.NewSeriesListDataFromValues(values2, charts.ChartTypeLine), Width: 500, Height: 400, Box: charts.Box{Left: 500, Top: 0, Right: 1000, Bottom: 400}, } // Create main painter p, _ := charts.NewPainter(charts.PainterOptions{ Type: charts.ChartOutputPNG, Width: 1000, Height: 400, }) // Render both charts opt1.Parent = p opt2.Parent = p charts.Render(opt1) charts.Render(opt2) data, _ := p.Bytes() ``` -------------------------------- ### Built-in Humanize Formatter Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Example of using a built-in formatter for human-readable numeric values. ```go // Returns "1.2K", "3.4M", etc. ``` -------------------------------- ### Font Fallback Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Demonstrates a fallback mechanism for fonts, ensuring a default font is used if a custom font cannot be loaded. ```go fontFamily := "CustomFont" charts.InstallFont(fontFamily, fontData) font, err := charts.GetFont(fontFamily) if err != nil { // Fallback to default font, _ = charts.GetDefaultFont() } ``` -------------------------------- ### Horizontal Bar Chart Example Source: https://github.com/vicanso/go-charts/blob/main/README.md Shows how to create a horizontal bar chart, including options for title, padding, legend labels, and Y-axis data. ```go package main import ( "github.com/vicanso/go-charts/v2" ) func main() { values := [][]float64{ { 18203, 23489, 29034, 104970, 131744, 630230, }, { // snip... }, } p, err := charts.HorizontalBarRender( values, charts.TitleTextOptionFunc("World Population"), charts.PaddingOptionFunc(charts.Box{ Top: 20, Right: 40, Bottom: 20, Left: 20, }), charts.LegendLabelsOptionFunc([]string{ "2011", "2012", }), charts.YAxisDataOptionFunc([]string{ "Brazil", "Indonesia", "USA", "India", "China", "World", }), ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } // snip... } ``` -------------------------------- ### X-Axis Show/Hide Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of hiding the X-axis using the 'Show' field. ```go xAxis.Show = charts.FalseFlag() // Hide the axis ``` -------------------------------- ### Line Chart from ECharts JSON Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a line chart by providing ECharts compatible JSON configuration. ```go json := `{ "title": { "text": "Sales Trend" }, "xAxis": { "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] }, "series": [{ "type": "line", "data": [150, 230, 224, 218, 135, 147, 260] }] }` data, err := charts.RenderEChartsToPNG(json) ``` -------------------------------- ### X-Axis Positioning Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Examples of setting the 'Position' field for an X-axis to move it to the top or bottom. ```go xAxis.Position = charts.PositionTop // Move to top xAxis.Position = charts.PositionBottom // Bottom (default) ``` -------------------------------- ### Bar Chart from ECharts JSON Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a bar chart by providing ECharts compatible JSON configuration. ```go json := `{ "title": {"text": "Monthly Revenue"}, "xAxis": { "type": "category", "data": ["Jan", "Feb", "Mar", "Apr", "May"] }, "yAxis": { "type": "value" }, "series": [{ "type": "bar", "data": [1000, 1200, 1500, 1800, 2100] }] }` data, err := charts.RenderEChartsToPNG(json) ``` -------------------------------- ### Series with Custom Styling Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Defines a series with specific styling, including stroke color, width, and marking the maximum point. ```go seriesList := charts.SeriesList{ { Type: charts.ChartTypeLine, Data: charts.NewSeriesDataFromValues([]float64{10, 20, 30}), Name: "Series 1", Style: charts.Style{ StrokeColor: charts.Color{R: 255, G: 0, B: 0, A: 255}, StrokeWidth: 2, }, MarkPoint: charts.NewMarkPoint(charts.SeriesMarkDataTypeMax), }, } ``` -------------------------------- ### NewMarkPoint Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates mark point configuration. ```go func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint ``` ```go mp := charts.NewMarkPoint( charts.SeriesMarkDataTypeMax, charts.SeriesMarkDataTypeMin, ) ``` -------------------------------- ### NewMarkLine Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates mark line configuration. ```go func NewMarkLine(markLineTypes ...string) SeriesMarkLine ``` ```go ml := charts.NewMarkLine( charts.SeriesMarkDataTypeAverage, charts.SeriesMarkDataTypeMax, ) ``` -------------------------------- ### NewXAxisOption Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates X-axis configuration. ```go func NewXAxisOption(data []string, boundaryGap ...*bool) XAxisOption ``` ```go opt := charts.NewXAxisOption( []string{"Jan", "Feb", "Mar"}, charts.TrueFlag(), ) ``` -------------------------------- ### GetDefaultFont Function Signature Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Gets the default font (pre-installed Roboto). ```go func GetDefaultFont() (*truetype.Font, error) ``` -------------------------------- ### NewLegendOption Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates legend configuration. ```go func NewLegendOption(labels []string, left ...string) LegendOption ``` ```go opt := charts.NewLegendOption( []string{"Series 1", "Series 2"}, charts.PositionRight, ) ``` -------------------------------- ### NewPieSeriesList Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates a series list for pie charts. ```go func NewPieSeriesList(values []float64) SeriesList ``` ```go values := []float64{1048, 735, 580, 484} seriesList := charts.NewPieSeriesList(values) p, _ := charts.PieRender(values) ``` -------------------------------- ### NewFunnelSeriesList Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates a series list for funnel charts. ```go func NewFunnelSeriesList(values []float64) SeriesList ``` ```go values := []float64{100, 80, 60, 40, 20} seriesList := charts.NewFunnelSeriesList(values) ``` -------------------------------- ### NewYAxisOptions Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates Y-axis configurations. ```go func NewYAxisOptions(data []string, others ...[]string) []YAxisOption ``` ```go opts := charts.NewYAxisOptions( []string{"A", "B", "C"}, []string{"1", "2", "3"}, ) ``` -------------------------------- ### PainterStyleOption function Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Sets initial style. ```go func PainterStyleOption(style Style) PainterOption ``` -------------------------------- ### NewSeriesLabelPainter Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates series label renderer. ```go func NewSeriesLabelPainter(params SeriesLabelPainterParams) *SeriesLabelPainter ``` -------------------------------- ### NewPainter Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Creates a new painter instance. ```go func NewPainter(opts PainterOptions, opt ...PainterOption) (*Painter, error) ``` ```go p, err := charts.NewPainter(charts.PainterOptions{ Type: charts.ChartOutputPNG, Width: 800, Height: 600, }) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Use Custom Font Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/00-overview-and-index.md Installs a custom font and renders a line chart using it. ```go charts.InstallFont("MyFont", fontData) p, _ := charts.LineRender(values, charts.FontFamilyOptionFunc("MyFont")) ``` -------------------------------- ### Child method Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Creates a child painter with inherited properties. ```go func (p *Painter) Child(opt ...PainterOption) *Painter ``` ```go child := p.Child( charts.PainterPaddingOption(charts.Box{Top: 20, Left: 20}), ) ``` -------------------------------- ### Series Type Field Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Examples of setting the 'Type' field for different chart types. ```go series.Type = charts.ChartTypeLine // "line" series.Type = charts.ChartTypeBar // "bar" series.Type = charts.ChartTypePie // "pie" series.Type = charts.ChartTypeRadar // "radar" series.Type = charts.ChartTypeFunnel // "funnel" series.Type = charts.ChartTypeHorizontalBar // "horizontalBar" ``` -------------------------------- ### TitleTextOptionFunc Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/02-option-functions.md Sets title and optional subtitle text. ```go func TitleTextOptionFunc(text string, subtext ...string) OptionFunc ``` ```go charts.TitleTextOptionFunc("Sales Dashboard", "Q1 2024") ``` -------------------------------- ### TitleOptionFunc Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/02-option-functions.md Sets complete title configuration with positioning and styling. ```go func TitleOptionFunc(title TitleOption) OptionFunc ``` ```go charts.TitleOptionFunc(charts.TitleOption{ Text: "Dashboard", Subtext: "Monthly Report", Left: charts.PositionCenter, Top: "20", }) ``` -------------------------------- ### Dual Y-Axis Chart Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Configures a chart with two independent Y-axes, each with its own min/max range and positioning. ```go opt := charts.ChartOption{ SeriesList: seriesList, XAxis: charts.NewXAxisOption(categories), YAxisOptions: []charts.YAxisOption{ { Min: FloatPtr(0), Max: FloatPtr(100), }, { Min: FloatPtr(0), Max: FloatPtr(1000), Position: charts.PositionRight, }, }, Title: charts.TitleOption{Text: "Multi-axis Chart"}, } p, err := charts.Render(opt) ``` -------------------------------- ### Pie Chart with Custom Legend Position Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a pie chart with a custom legend position. ```go p, err := charts.PieRender( values, charts.LegendOptionFunc(charts.LegendOption{ Data: []string{"Search", "Direct", "Email", "Ads"}, Orient: charts.OrientVertical, Left: charts.PositionLeft, Top: charts.PositionCenter, }), ) ``` -------------------------------- ### Creating Series from Raw Values Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Demonstrates how to create a single series or multiple series directly from raw float64 values. ```go // Single series series := charts.NewSeriesFromValues([]float64{10, 20, 30}) // Multiple series seriesList := charts.NewSeriesListDataFromValues([][]float64{ {10, 20, 30}, {15, 25, 35}, }) ``` -------------------------------- ### Grouped Bar Chart Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Renders a grouped bar chart comparing two sets of data. ```go values := [][]float64{ {2.0, 4.9, 7.0, 23.2, 25.6}, // Group 1 {1.5, 3.2, 5.5, 20.1, 22.8}, // Group 2 } p, err := charts.BarRender( values, charts.XAxisDataOptionFunc([]string{"Jan", "Feb", "Mar", "Apr", "May"}), charts.LegendLabelsOptionFunc([]string{"2023", "2024"}), charts.TitleTextOptionFunc("Monthly Rainfall Comparison"), ) ``` -------------------------------- ### Get Min/Max Values from Series Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Retrieving the minimum and maximum values for a given Y-axis. ```go max, min := seriesList.GetMaxMin(0) // For first Y-axis ``` -------------------------------- ### NewGridPainter Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates grid renderer for table layouts. ```go func NewGridPainter(p *Painter, opt GridPainterOption) *gridPainter ``` ```go grid := charts.NewGridPainter(p, charts.GridPainterOption{ Column: 3, Row: 4, StrokeWidth: 1, StrokeColor: charts.Color{R: 200, G: 200, B: 200, A: 255}, }) ``` -------------------------------- ### Series Name Field Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of setting the 'Name' field for a series, which is used in the legend and labels. ```go series.Name = "Revenue" // Appears in legend ``` -------------------------------- ### ThemeOptionFunc Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/02-option-functions.md Sets chart theme. ```go func ThemeOptionFunc(theme string) OptionFunc ``` ```go charts.ThemeOptionFunc("dark") ``` -------------------------------- ### Custom Value Formatter Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Applies a custom function to format the display of values on the chart axes or tooltips. ```go opt := charts.ChartOption{ SeriesList: seriesList, ValueFormatter: func(v float64) string { if v > 1000000 { return fmt.Sprintf("%.1fM", v/1000000) } else if v > 1000 { return fmt.Sprintf("%.1fK", v/1000) } return fmt.Sprintf("%.0f", v) }, } p, err := charts.Render(opt) ``` -------------------------------- ### PainterOptions struct Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Configuration struct for painter creation. ```go type PainterOptions struct { Type string Width int Height int Font *truetype.Font } ``` -------------------------------- ### LineChartOption Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Configuration options for rendering a line chart. ```go type LineChartOption struct { Theme ColorPalette Font *truetype.Font SeriesList SeriesList XAxis XAxisOption Padding Box YAxisOptions []YAxisOption Title TitleOption Legend LegendOption SymbolShow *bool StrokeWidth float64 FillArea bool backgroundIsFilled bool Opacity uint8 } ``` -------------------------------- ### Pie Series Data Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/06-echarts-compatibility.md Example of data format for pie charts, where each data item becomes a separate series. ```json { "series": [{ "type": "pie", "data": [ {"value": 1048, "name": "Search Engine"}, {"value": 735, "name": "Direct"}, {"value": 580, "name": "Email"} ] }] } ``` -------------------------------- ### NewSeriesFromValues Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates a single series from numeric array. ```go func NewSeriesFromValues(values []float64, chartType ...string) Series ``` ```go series := charts.NewSeriesFromValues([]float64{10, 20, 30}, charts.ChartTypeBar) ``` -------------------------------- ### Line/Bar Series Data (Named and Colored) Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/06-echarts-compatibility.md Example of data items with values and names for line or bar series. ```json { "series": [{ "data": [ {"value": 100, "name": "Item A"}, {"value": 200, "name": "Item B"} ] }] } ``` -------------------------------- ### SeriesList Type Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/03-types-and-structures.md An array of Series with helper methods for filtering, retrieving names, and getting axis value ranges. ```go type SeriesList []Series ``` -------------------------------- ### Performance Benchmarks Source: https://github.com/vicanso/go-charts/blob/main/README.md Benchmarks showing the time per operation (ns/op), bytes per operation (B/op), and allocations per operation (allocs/op) for rendering multi-charts in PNG and SVG formats. ```bash BenchmarkMultiChartPNGRender-8 78 15216336 ns/op 2298308 B/op 1148 allocs/op BenchmarkMultiChartSVGRender-8 367 3356325 ns/op 20597282 B/op 3088 allocs/op ``` -------------------------------- ### Dark Theme with Custom Colors Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/08-usage-patterns-and-examples.md Applies a dark theme to a line chart and customizes background and title colors. ```go p, err := charts.LineRender( values, charts.ThemeOptionFunc(charts.ThemeDark), charts.BackgroundColorOptionFunc(charts.Color{ R: 30, G: 30, B: 40, A: 255, // Dark navy }), charts.TitleOptionFunc(charts.TitleOption{ Text: "Dashboard", FontColor: charts.Color{R: 255, G: 255, B: 255, A: 255}, }), ) ``` -------------------------------- ### Line/Bar Series Data (Simple Numeric Array) Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/06-echarts-compatibility.md Example of a simple numeric array for line or bar series data. ```json { "series": [{ "data": [10, 20, 30, 40] // Simple numeric array }] } ``` -------------------------------- ### PieChartOption Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Configuration options for rendering a pie chart. ```go type PieChartOption struct { Theme ColorPalette Font *truetype.Font SeriesList SeriesList Padding Box Title TitleOption Legend LegendOption backgroundIsFilled bool } ``` -------------------------------- ### Rotated Category Labels Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of rotating category labels on an axis, shown here for an X-axis, by setting the TextRotation property. ```go xAxis.TextRotation = math.Pi / 4 // 45 degrees ``` -------------------------------- ### Creating Pie Chart Series Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Illustrates how to create a series list for a pie chart from a slice of values, where each value becomes a separate series. ```go values := []float64{1000, 800, 600} // Creates 3 series internally: // Series 0: value=1000 // Series 1: value=800 // Series 2: value=600 seriesList := charts.NewPieSeriesList(values) ``` -------------------------------- ### Category Y-Axis (Horizontal Bar) Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of creating a Y-axis with string categories, suitable for horizontal bar charts. ```go yAxis := charts.NewYAxisOptions([]string{ "Product A", "Product B", "Product C", }) ``` -------------------------------- ### Creating Series from SeriesData Array Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Shows how to construct a series using a slice of SeriesData, allowing for individual data point styling. ```go data := []charts.SeriesData{ {Value: 100, Style: charts.Style{...}}, {Value: 200, Style: charts.Style{...}}, } series := charts.Series{ Type: charts.ChartTypeLine, Data: data, Name: "Sales", } ``` -------------------------------- ### InstallFont Function Signature Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/05-fonts-and-themes.md Registers a custom font for use in charts. ```go func InstallFont(fontFamily string, data []byte) error ``` -------------------------------- ### Series Min/Max Fields Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of overriding the axis range for a specific series using 'Min' and 'Max' fields. ```go min := 0.0 max := 1000.0 series.Min = &min series.Max = &max ``` -------------------------------- ### NewRange Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/07-utilities-and-configuration.md Creates axis range calculator. ```go func NewRange(opt AxisRangeOption) axisRange ``` ```go r := charts.NewRange(charts.AxisRangeOption{ Painter: p, Min: 0, Max: 100, Size: 500, DivideCount: 5, }) values := r.Values() // Get axis label values ``` -------------------------------- ### PainterThemeOption function Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Sets color theme. ```go func PainterThemeOption(theme ColorPalette) PainterOption ``` -------------------------------- ### Thousand-Separator Y-Axis Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of using a custom ValueFormatter for a Y-axis to format numbers, in this case, to display them without decimal places. ```go opt := charts.ChartOption{ ValueFormatter: func(v float64) string { return fmt.Sprintf("%.0f", v) }, } ``` -------------------------------- ### Series Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/03-types-and-structures.md Data series configuration. ```go type Series struct { Type string Data []SeriesData AxisIndex int Style chart.Style Label SeriesLabel Name string Radius string RoundRadius int MarkPoint SeriesMarkPoint MarkLine SeriesMarkLine Min *float64 Max *float64 } ``` -------------------------------- ### Series Style Field Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of customizing the visual style of a series, including stroke color, width, and fill color. ```go series.Style = charts.Style{ StrokeColor: charts.Color{R: 255, G: 0, B: 0, A: 255}, StrokeWidth: 2, FillColor: charts.Color{R: 255, G: 200, B: 200, A: 100}, } ``` -------------------------------- ### SetTextStyle method Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/04-painter-and-rendering.md Sets text-specific styling. ```go func (p *Painter) SetTextStyle(style Style) *Painter ``` -------------------------------- ### Simple Series Label Formatting Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Basic configuration for displaying series names as labels. ```go series.Label = charts.SeriesLabel{ Show: true, Formatter: "{b}", // Just the name } ``` -------------------------------- ### TitleOption Structure Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/03-types-and-structures.md Configuration for title and subtitle in Go-charts. ```go type TitleOption struct { Theme ColorPalette Text string Subtext string Left string Top string Font *truetype.Font FontSize float64 FontColor Color SubtextFontSize float64 SubtextFontColor Color } ``` -------------------------------- ### SplitLineShow for Grid Lines Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Controlling the visibility of grid lines. ```go yAxis.SplitLineShow = charts.TrueFlag() // Show lines yAxis.SplitLineShow = charts.FalseFlag() // Hide lines ``` -------------------------------- ### Series Radius Field (Pie Charts) Source: https://github.com/vicanso/go-charts/blob/main/_autodocs/09-series-axes-legend-reference.md Example of setting the 'Radius' field for pie chart series to control the size of the pie. ```go series.Radius = "50%" // Pie radius series.Radius = "30%" // Smaller pie ```