{"id":13461351,"url":"https://github.com/vicanso/go-charts","last_synced_at":"2025-04-05T21:06:55.237Z","repository":{"id":37050381,"uuid":"436606384","full_name":"vicanso/go-charts","owner":"vicanso","description":"A charts library for Golang","archived":false,"fork":false,"pushed_at":"2024-08-15T12:40:18.000Z","size":2949,"stargazers_count":265,"open_issues_count":20,"forks_count":42,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-29T20:05:07.346Z","etag":null,"topics":["chart","charting-library","charts","echarts","go","go-chart","go-charts","golang","svg"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vicanso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-09T12:20:33.000Z","updated_at":"2025-03-28T04:19:33.000Z","dependencies_parsed_at":"2024-03-09T01:26:11.730Z","dependency_job_id":"8af2f2a3-7152-45e1-9506-97be6dc4b9ea","html_url":"https://github.com/vicanso/go-charts","commit_stats":null,"previous_names":["vicanso/go-echarts","vicanso/go-chart"],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fgo-charts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fgo-charts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fgo-charts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fgo-charts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicanso","download_url":"https://codeload.github.com/vicanso/go-charts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399873,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chart","charting-library","charts","echarts","go","go-chart","go-charts","golang","svg"],"created_at":"2024-07-31T11:00:35.558Z","updated_at":"2025-04-05T21:06:55.216Z","avatar_url":"https://github.com/vicanso.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# go-charts\n\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vicanso/go-charts/blob/master/LICENSE)\n[![Build Status](https://github.com/vicanso/go-charts/workflows/Test/badge.svg)](https://github.com/vicanso/go-charts/actions)\n\n[中文](./README_zh.md)\n\n`go-charts` base on [go-chart](https://github.com/wcharczuk/go-chart)，it is simpler way for generating charts, which supports `svg` and `png` format and themes: `light`, `dark`, `grafana` and `ant`. The default format is `png` and the default theme is `light`.\n\n`Apache ECharts` is popular among Front-end developers, so `go-charts` supports the option of `Apache ECharts`. Developers can generate charts almost the same as `Apache ECharts`. \n\nScreenshot of common charts, the left part is light theme, the right part is grafana theme.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./assets/go-charts.png\" alt=\"go-charts\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./assets/go-table.png\" alt=\"go-table\"\u003e\n\u003c/p\u003e\n\n## Chart Type\n\nThese chart types are supported: `line`, `bar`, `horizontal bar`, `pie`, `radar` or `funnel` and `table`.\n\n## Example\n\nMore examples can be found in the [./examples/](./examples/) directory.\n\n\n### Line Chart\n```go\npackage main\n\nimport (\n\tcharts \"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := [][]float64{\n\t\t{\n\t\t\t120,\n\t\t\t132,\n\t\t\t101,\n\t\t\t134,\n\t\t\t90,\n\t\t\t230,\n\t\t\t210,\n\t\t},\n\t\t{\n\t\t\t// snip...\n\t\t},\n\t\t{\n\t\t\t// snip...\n\t\t},\n\t\t{\n\t\t\t// snip...\n\t\t},\n\t\t{\n\t\t\t// snip...\n\t\t},\n\t}\n\tp, err := charts.LineRender(\n\t\tvalues,\n\t\tcharts.TitleTextOptionFunc(\"Line\"),\n\t\tcharts.XAxisDataOptionFunc([]string{\n\t\t\t\"Mon\",\n\t\t\t\"Tue\",\n\t\t\t\"Wed\",\n\t\t\t\"Thu\",\n\t\t\t\"Fri\",\n\t\t\t\"Sat\",\n\t\t\t\"Sun\",\n\t\t}),\n\t\tcharts.LegendLabelsOptionFunc([]string{\n\t\t\t\"Email\",\n\t\t\t\"Union Ads\",\n\t\t\t\"Video Ads\",\n\t\t\t\"Direct\",\n\t\t\t\"Search Engine\",\n\t\t}, charts.PositionCenter),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### Bar Chart\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := [][]float64{\n\t\t{\n\t\t\t2.0,\n\t\t\t4.9,\n\t\t\t7.0,\n\t\t\t23.2,\n\t\t\t25.6,\n\t\t\t76.7,\n\t\t\t135.6,\n\t\t\t162.2,\n\t\t\t32.6,\n\t\t\t20.0,\n\t\t\t6.4,\n\t\t\t3.3,\n\t\t},\n\t\t{\n\t\t\t// snip...\t\n\t\t},\n\t}\n\tp, err := charts.BarRender(\n\t\tvalues,\n\t\tcharts.XAxisDataOptionFunc([]string{\n\t\t\t\"Jan\",\n\t\t\t\"Feb\",\n\t\t\t\"Mar\",\n\t\t\t\"Apr\",\n\t\t\t\"May\",\n\t\t\t\"Jun\",\n\t\t\t\"Jul\",\n\t\t\t\"Aug\",\n\t\t\t\"Sep\",\n\t\t\t\"Oct\",\n\t\t\t\"Nov\",\n\t\t\t\"Dec\",\n\t\t}),\n\t\tcharts.LegendLabelsOptionFunc([]string{\n\t\t\t\"Rainfall\",\n\t\t\t\"Evaporation\",\n\t\t}, charts.PositionRight),\n\t\tcharts.MarkLineOptionFunc(0, charts.SeriesMarkDataTypeAverage),\n\t\tcharts.MarkPointOptionFunc(0, charts.SeriesMarkDataTypeMax,\n\t\t\tcharts.SeriesMarkDataTypeMin),\n\t\t// custom option func\n\t\tfunc(opt *charts.ChartOption) {\n\t\t\topt.SeriesList[1].MarkPoint = charts.NewMarkPoint(\n\t\t\t\tcharts.SeriesMarkDataTypeMax,\n\t\t\t\tcharts.SeriesMarkDataTypeMin,\n\t\t\t)\n\t\t\topt.SeriesList[1].MarkLine = charts.NewMarkLine(\n\t\t\t\tcharts.SeriesMarkDataTypeAverage,\n\t\t\t)\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### Horizontal Bar Chart\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := [][]float64{\n\t\t{\n\t\t\t18203,\n\t\t\t23489,\n\t\t\t29034,\n\t\t\t104970,\n\t\t\t131744,\n\t\t\t630230,\n\t\t},\n\t\t{\n\t\t\t// snip...\t\n\t\t},\n\t}\n\tp, err := charts.HorizontalBarRender(\n\t\tvalues,\n\t\tcharts.TitleTextOptionFunc(\"World Population\"),\n\t\tcharts.PaddingOptionFunc(charts.Box{\n\t\t\tTop:    20,\n\t\t\tRight:  40,\n\t\t\tBottom: 20,\n\t\t\tLeft:   20,\n\t\t}),\n\t\tcharts.LegendLabelsOptionFunc([]string{\n\t\t\t\"2011\",\n\t\t\t\"2012\",\n\t\t}),\n\t\tcharts.YAxisDataOptionFunc([]string{\n\t\t\t\"Brazil\",\n\t\t\t\"Indonesia\",\n\t\t\t\"USA\",\n\t\t\t\"India\",\n\t\t\t\"China\",\n\t\t\t\"World\",\n\t\t}),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### Pie Chart\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := []float64{\n\t\t1048,\n\t\t735,\n\t\t580,\n\t\t484,\n\t\t300,\n\t}\n\tp, err := charts.PieRender(\n\t\tvalues,\n\t\tcharts.TitleOptionFunc(charts.TitleOption{\n\t\t\tText:    \"Rainfall vs Evaporation\",\n\t\t\tSubtext: \"Fake Data\",\n\t\t\tLeft:    charts.PositionCenter,\n\t\t}),\n\t\tcharts.PaddingOptionFunc(charts.Box{\n\t\t\tTop:    20,\n\t\t\tRight:  20,\n\t\t\tBottom: 20,\n\t\t\tLeft:   20,\n\t\t}),\n\t\tcharts.LegendOptionFunc(charts.LegendOption{\n\t\t\tOrient: charts.OrientVertical,\n\t\t\tData: []string{\n\t\t\t\t\"Search Engine\",\n\t\t\t\t\"Direct\",\n\t\t\t\t\"Email\",\n\t\t\t\t\"Union Ads\",\n\t\t\t\t\"Video Ads\",\n\t\t\t},\n\t\t\tLeft: charts.PositionLeft,\n\t\t}),\n\t\tcharts.PieSeriesShowLabel(),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\t\n}\n```\n\n### Radar Chart\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := [][]float64{\n\t\t{\n\t\t\t4200,\n\t\t\t3000,\n\t\t\t20000,\n\t\t\t35000,\n\t\t\t50000,\n\t\t\t18000,\n\t\t},\n\t\t{\n\t\t\t// snip...\n\t\t},\n\t}\n\tp, err := charts.RadarRender(\n\t\tvalues,\n\t\tcharts.TitleTextOptionFunc(\"Basic Radar Chart\"),\n\t\tcharts.LegendLabelsOptionFunc([]string{\n\t\t\t\"Allocated Budget\",\n\t\t\t\"Actual Spending\",\n\t\t}),\n\t\tcharts.RadarIndicatorOptionFunc([]string{\n\t\t\t\"Sales\",\n\t\t\t\"Administration\",\n\t\t\t\"Information Technology\",\n\t\t\t\"Customer Support\",\n\t\t\t\"Development\",\n\t\t\t\"Marketing\",\n\t\t}, []float64{\n\t\t\t6500,\n\t\t\t16000,\n\t\t\t30000,\n\t\t\t38000,\n\t\t\t52000,\n\t\t\t25000,\n\t\t}),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### Funnel Chart\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tvalues := []float64{\n\t\t100,\n\t\t80,\n\t\t60,\n\t\t40,\n\t\t20,\n\t}\n\tp, err := charts.FunnelRender(\n\t\tvalues,\n\t\tcharts.TitleTextOptionFunc(\"Funnel\"),\n\t\tcharts.LegendLabelsOptionFunc([]string{\n\t\t\t\"Show\",\n\t\t\t\"Click\",\n\t\t\t\"Visit\",\n\t\t\t\"Inquiry\",\n\t\t\t\"Order\",\n\t\t}),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### Table\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\theader := []string{\n\t\t\"Name\",\n\t\t\"Age\",\n\t\t\"Address\",\n\t\t\"Tag\",\n\t\t\"Action\",\n\t}\n\tdata := [][]string{\n\t\t{\n\t\t\t\"John Brown\",\n\t\t\t\"32\",\n\t\t\t\"New York No. 1 Lake Park\",\n\t\t\t\"nice, developer\",\n\t\t\t\"Send Mail\",\n\t\t},\n\t\t{\n\t\t\t\"Jim Green\t\",\n\t\t\t\"42\",\n\t\t\t\"London No. 1 Lake Park\",\n\t\t\t\"wow\",\n\t\t\t\"Send Mail\",\n\t\t},\n\t\t{\n\t\t\t\"Joe Black\t\",\n\t\t\t\"32\",\n\t\t\t\"Sidney No. 1 Lake Park\",\n\t\t\t\"cool, teacher\",\n\t\t\t\"Send Mail\",\n\t\t},\n\t}\n\tspans := map[int]int{\n\t\t0: 2,\n\t\t1: 1,\n\t\t// 设置第三列的span\n\t\t2: 3,\n\t\t3: 2,\n\t\t4: 2,\n\t}\n\tp, err := charts.TableRender(\n\t\theader,\n\t\tdata,\n\t\tspans,\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tbuf, err := p.Bytes()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// snip...\n}\n```\n\n### ECharts Render\n\n```go\npackage main\n\nimport (\n\t\"github.com/vicanso/go-charts/v2\"\n)\n\nfunc main() {\n\tbuf, err := charts.RenderEChartsToPNG(`{\n\t\t\"title\": {\n\t\t\t\"text\": \"Line\"\n\t\t},\n\t\t\"xAxis\": {\n\t\t\t\"data\": [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"]\n\t\t},\n\t\t\"series\": [\n\t\t\t{\n\t\t\t\t\"data\": [150, 230, 224, 218, 135, 147, 260]\n\t\t\t}\n\t\t]\n\t}`)\n\t// snip...\n}\n```\n\n## ECharts Option\n\nThe name with `[]` is new parameter, others are the same as `echarts`.\n\n- `[type]` The canvas type, support `svg` and `png`, default is `svg`\n- `[theme]` The theme, support `dark`, `light` and `grafana`, default is `light`\n- `[fontFamily]` The font family for chart\n- `[padding]` The padding of chart\n- `[box]` The canvas box of chart\n- `[width]` The width of chart\n- `[height]` The height of chart\n- `title` Title component, including main title and subtitle\n  - `title.text` The main title text, supporting for \\n for newlines\n  - `title.subtext`Subtitle text, supporting for \\n for newlines\n  - `title.left` Distance between title component and the left side of the container. Left value can be instant pixel value like 20; it can also be a percentage value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.\n  - `title.top` Distance between title component and the top side of the container. Top value can be instant pixel value like 20\n  - `title.textStyle.color` Text color for title\n  - `title.textStyle.fontSize` Text font size for title \n  - `title.textStyle.fontFamily` Text font family for title, it will change the font family for chart\n- `xAxis` The x axis in cartesian(rectangular) coordinate. `go-charts` only support one x axis.\n  - `xAxis.boundaryGap` The boundary gap on both sides of a coordinate axis. The setting and behavior of category axes and non-category axes are different. If set `null` or `true`, the label appear in the center part of two axis ticks.\n  - `xAxis.splitNumber` Number of segments that the axis is split into. Note that this number serves only as a recommendation, and the true segments may be adjusted based on readability\n  - `xAxis.data` Category data, only support string array.\n- `yAxis` The y axis in cartesian(rectangular) coordinate, it support 2 y axis\n  - `yAxis.min` The minimum value of axis. It will be automatically computed to make sure axis tick is equally distributed when not set\n  - `yAxis.max` The maximum value of axis. It will be automatically computed to make sure axis tick is equally distributed when not se.\n  - `yAxis.axisLabel.formatter` Formatter of axis label, which supports string template: `\"formatter\": \"{value} kg\"`\n  - `yAxis.axisLine.lineStyle.color` The color for line\n- `legend` Legend component\n  - `legend.show` Whether to show legend\n  - `legend.data` Data array of legend, only support string array: [\"Email\", \"Video Ads\"]\n  - `legend.align` Legend marker and text aligning. Support `left` and `right`, default is `left`\n  - `legend.padding` legend space around content\n  - `legend.left` Distance between legend component and the left side of the container. Left value can be instant pixel value like 20; it can also be a percentage value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.\n  - `legend.top` Distance between legend component and the top side of the container. Top value can be instant pixel value like 20\n- `radar` Coordinate for radar charts\n  - `radar.indicator` Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart\n    - `radar.indicator.name` Indicator's name\n    - `radar.indicator.max` The maximum value of indicator\n    - `radar.indicator.min` The minimum value of indicator, default value is 0.\n- `series` The series for chart \n  - `series.name` Series name used for displaying in legend.\n  - `series.type` Series type: `line`, `bar`, `pie`, `radar` or `funnel`\n  - `series.radius` Radius of Pie chart:`50%`, default is `40%`\n  - `series.yAxisIndex` Index of y axis to combine with, which is useful for multiple y axes in one chart\n  - `series.label.show` Whether to show label\n  - `series.label.distance` Distance to the host graphic element\n  - `series.label.color` Label color\n  - `series.itemStyle.color` Color for the series's item \n  - `series.markPoint` Mark point in a chart.\n  - `series.markPoint.symbolSize` Symbol size, default is `30` \n  - `series.markPoint.data` Data array for mark points, each of which is an object and the type only support `max` and `min`: `[{\"type\": \"max\"}, {\"type\": \"min\"}]`\n  - `series.markLine` Mark line in a chart\n  - `series.markPoint.data`  Data array for mark points, each of which is an object and the type only support `max`, `min` and `average`: `[{\"type\": \"max\"}, {\"type\": \"min\"}, {\"type\": \"average\"}]``\n  - `series.data` Data array of series, which can be in the following forms:\n    - `value` It's a float array: [1.1, 2,3, 5.2]\n    - `object` It's a object value array: [{\"value\": 1048, \"name\": \"Search Engine\"},{\"value\": 735,\"name\": \"Direct\"}]\n- `[children]` The options of children chart\n\n\n## Performance\n\nGenerate a png chart will be less than 20ms. It's better than using `chrome headless` with `echarts`.\n\n```bash\nBenchmarkMultiChartPNGRender-8                78          15216336 ns/op         2298308 B/op       1148 allocs/op\nBenchmarkMultiChartSVGRender-8               367           3356325 ns/op        20597282 B/op       3088 allocs/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fgo-charts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicanso%2Fgo-charts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fgo-charts/lists"}