{"id":16618602,"url":"https://github.com/brentp/go-chartjs","last_synced_at":"2025-03-16T22:30:31.209Z","repository":{"id":45770291,"uuid":"73836250","full_name":"brentp/go-chartjs","owner":"brentp","description":"golang library to make https://chartjs.org/ plots (this is vanilla #golang, not gopherjs)","archived":false,"fork":false,"pushed_at":"2020-10-15T23:01:57.000Z","size":30,"stargazers_count":48,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T14:47:52.057Z","etag":null,"topics":["chart","chartjs","golang","plot","plotting"],"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/brentp.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}},"created_at":"2016-11-15T17:04:12.000Z","updated_at":"2023-09-30T14:09:11.000Z","dependencies_parsed_at":"2022-08-30T23:20:13.053Z","dependency_job_id":null,"html_url":"https://github.com/brentp/go-chartjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fgo-chartjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fgo-chartjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fgo-chartjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentp%2Fgo-chartjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brentp","download_url":"https://codeload.github.com/brentp/go-chartjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830952,"owners_count":20354854,"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","chartjs","golang","plot","plotting"],"created_at":"2024-10-12T02:20:49.251Z","updated_at":"2025-03-16T22:30:30.929Z","avatar_url":"https://github.com/brentp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"chartjs\n-------\n\ngo wrapper for [chartjs](http://chartjs.org)\n\n[![GoDoc](https://godoc.org/github.com/brentp/go-chartjs?status.png)](https://godoc.org/github.com/brentp/go-chartjs)\n[![Build Status](https://travis-ci.org/brentp/go-chartjs.svg)](https://travis-ci.org/brentp/go-chartjs)\n\n\nChartjs charts are defined purely in JSON, so this library is mostly\nstructs and struct-tags that dictate how to marshal to JSON. None of the currently\nimplemented parts are stringly-typed in this library so it can avoid many errors.\n\nThe chartjs javascript/JSON api has a [lot of surface area](http://www.chartjs.org/docs/).\nCurrently, only the options that I use are provided. More can and will be added as I need\nthem (or via pull-requests).\n\nThere is a small amount of code to simplify creating charts.\n\ndata to be plotted by chartjs has to meet this interface.\n```Go\n  type Values interface {\n      // X-axis values. If only these are specified then it must be a Bar plot.\n      Xs() []float64\n      // Optional Y values.\n      Ys() []float64\n      // Rs are used to size points for chartType `Bubble`. If this returns an\n      // empty slice then it's not used.\n      Rs() []float64\n  }\n```\n\nExample\n-------\n\nThis longish example shows common use of the library.\n\n```Go\npackage main\n\nimport (\n\t\"log\"\n\t\"math\"\n\t\"os\"\n\n\tchartjs \"github.com/brentp/go-chartjs\"\n)\n\n// satisfy the required interface with this struct and methods.\ntype xy struct {\n\tx []float64\n\ty []float64\n\tr []float64\n}\n\nfunc (v xy) Xs() []float64 {\n\treturn v.x\n}\nfunc (v xy) Ys() []float64 {\n\treturn v.y\n}\nfunc (v xy) Rs() []float64 {\n\treturn v.r\n}\n\nfunc check(e error) {\n\tif e != nil {\n\t\tlog.Fatal(e)\n\t}\n}\n\nfunc main() {\n\tvar xys1 xy\n\tvar xys2 xy\n\n    // make some example data.\n\tfor i := float64(0); i \u003c 9; i += 0.1 {\n\t\txys1.x = append(xys1.x, i)\n\t\txys2.x = append(xys2.x, i)\n\n\t\txys1.y = append(xys1.y, math.Sin(i))\n\t\txys2.y = append(xys2.y, 3*math.Cos(2*i))\n\n\t}\n\n\t// a set of colors to work with.\n\tcolors := []*types.RGBA{\n\t\t\u0026types.RGBA{102, 194, 165, 220},\n\t\t\u0026types.RGBA{250, 141, 98, 220},\n\t\t\u0026types.RGBA{141, 159, 202, 220},\n\t\t\u0026types.RGBA{230, 138, 195, 220},\n\t}\n\n\t// a Dataset contains the data and styling info.\n\td1 := chartjs.Dataset{Data: xys1, BorderColor: colors[1], Label: \"sin(x)\", Fill: chartjs.False,\n\t\tPointRadius: 10, PointBorderWidth: 4, BackgroundColor: colors[0]}\n\n\td2 := chartjs.Dataset{Data: xys2, BorderWidth: 8, BorderColor: colors[3], Label: \"3*cos(2*x)\",\n\t\tFill: chartjs.False, PointStyle: chartjs.Star}\n\n\tchart := chartjs.Chart{Label: \"test-chart\"}\n\n\tvar err error\n\t_, err = chart.AddXAxis(chartjs.Axis{Type: chartjs.Linear, Position: chartjs.Bottom, ScaleLabel: \u0026chartjs.ScaleLabel{FontSize: 22, LabelString: \"X\", Display: chartjs.True}})\n\tcheck(err)\n\td1.YAxisID, err = chart.AddYAxis(chartjs.Axis{Type: chartjs.Linear, Position: chartjs.Left,\n\t\tScaleLabel: \u0026chartjs.ScaleLabel{LabelString: \"sin(x)\", Display: chartjs.True}})\n\tcheck(err)\n\tchart.AddDataset(d1)\n\n\td2.YAxisID, err = chart.AddYAxis(chartjs.Axis{Type: chartjs.Linear, Position: chartjs.Right,\n\t\tScaleLabel: \u0026chartjs.ScaleLabel{LabelString: \"3*cos(2*x)\", Display: chartjs.True}})\n\tcheck(err)\n\tchart.AddDataset(d2)\n\n\tchart.Options.Responsive = chartjs.False\n\n\twtr, err := os.Create(\"example-chartjs-multi.html\")\n\tif err != nil {\n\t}\n\tif err := chart.SaveHTML(wtr, nil); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\twtr.Close()\n}\n```\n\nThe resulting html will have an interactive `\u003ccanvas\u003e` element that looks like this.\n\n![plot](https://cloud.githubusercontent.com/assets/1739/20368217/5068a336-ac10-11e6-8d6c-f711c7c71df3.png \"example plot\")\n\n\nLive Examples\n-------------\n\n[evaluating coverage on high throughput sequencing data](https://brentp.github.io/goleft/indexcov/ex-indexcov-roc.html)\n\n[inferring sex from sequencing coverage on X and Y chroms](https://brentp.github.io/goleft/indexcov/ex-indexcov-sex.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fgo-chartjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrentp%2Fgo-chartjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentp%2Fgo-chartjs/lists"}