<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AChart_data%2Fdoc</id>
	<title>Template:Chart data/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AChart_data%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Template:Chart_data/doc&amp;action=history"/>
	<updated>2026-04-30T12:36:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Template:Chart_data/doc&amp;diff=35561&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;{{documentation}}  &#039;&#039;&#039;Chart data&#039;&#039;&#039; is a template that displays a chart on a wiki page, using [https://www.chartjs.org/ Chart.js] through MediaWiki:Gadget-Charts-core.js.  While you can construct the JSON for the script yourself, this template is intended to make constructing it easier by providing the wrapper and allowing you to write the configuration in lua.  ==Usage== &lt;pre&gt;{{Chart data|module name|width=width of chart|height=height of chart}}&lt;/pre&gt;  The module na...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Template:Chart_data/doc&amp;diff=35561&amp;oldid=prev"/>
		<updated>2024-10-16T23:21:13Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{documentation}}  &amp;#039;&amp;#039;&amp;#039;Chart data&amp;#039;&amp;#039;&amp;#039; is a template that displays a chart on a wiki page, using [https://www.chartjs.org/ Chart.js] through &lt;a href=&quot;/w/MediaWiki:Gadget-Charts-core.js&quot; title=&quot;MediaWiki:Gadget-Charts-core.js&quot;&gt;MediaWiki:Gadget-Charts-core.js&lt;/a&gt;.  While you can construct the JSON for the script yourself, this template is intended to make constructing it easier by providing the wrapper and allowing you to write the configuration in lua.  ==Usage== &amp;lt;pre&amp;gt;{{Chart data|module name|width=width of chart|height=height of chart}}&amp;lt;/pre&amp;gt;  The module na...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{documentation}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chart data&amp;#039;&amp;#039;&amp;#039; is a template that displays a chart on a wiki page, using [https://www.chartjs.org/ Chart.js] through [[MediaWiki:Gadget-Charts-core.js]].&lt;br /&gt;
&lt;br /&gt;
While you can construct the JSON for the script yourself, this template is intended to make constructing it easier by providing the wrapper and allowing you to write the configuration in lua.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&amp;lt;pre&amp;gt;{{Chart data|module name|width=width of chart|height=height of chart}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The module name (Module: optional) is the name of a data module that returns the full configuration of the chart as a [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.loadData &amp;lt;code&amp;gt;mw.loadData&amp;lt;/code&amp;gt;]-compatible table. Chart data will then load that module and encode it into JSON with [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.text.jsonEncode &amp;lt;code&amp;gt;mw.text.jsonEncode&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Optional parameters height and width can be used to specify the height and width of the chart, using any unit. Ideally these should try to avoid fixed widths (px) and use relative units instead (%, vh, vw).&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&amp;lt;pre&amp;gt;{{Chart data|Chart data/xp chart|width=40vw|height=40vh}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will load [[Module:Chart data/xp chart]] and provide 40vw width and 40vh height.&lt;br /&gt;
&lt;br /&gt;
{{Chart data|Chart data/xp chart|width=40vw|height=40vh}}&lt;br /&gt;
&lt;br /&gt;
==Constructing a chart==&lt;br /&gt;
Data for a chart can be stored in any module - using a subpage of [[Module:Chart data]] (eg [[Module:Chart data/xp chart]]) is a convenient place if no other location is appropriate.&lt;br /&gt;
&lt;br /&gt;
The returned table has three main fields in the top level table: &amp;lt;tt&amp;gt;type&amp;lt;/tt&amp;gt;, which specifies the chart type; &amp;lt;tt&amp;gt;data&amp;lt;/tt&amp;gt; which specifies all the data used in the chart; and &amp;lt;tt&amp;gt;options&amp;lt;/tt&amp;gt; which spcifies any other configuration used in the chart. One should refer to [https://www.chartjs.org/docs/latest/ the full Chart.js documentation] for all possible options - everything except function types are supported.&lt;br /&gt;
&lt;br /&gt;
===Common things to change===&lt;br /&gt;
;Change axes labels&lt;br /&gt;
The axes labels are found in key &amp;lt;code&amp;gt;options.scales.xAxes[#].scaleLabel.labelString&amp;lt;/code&amp;gt;. xAxes and yAxes are arrays, so you can set separate labels for each axis. You may also need to set &amp;lt;code&amp;gt;...scaleLabel.display = true&amp;lt;/code&amp;gt; to make the labels show up.&lt;br /&gt;
&lt;br /&gt;
;Change tooltips&lt;br /&gt;
Tooltip options are in key &amp;lt;code&amp;gt;options.tooltips&amp;lt;/code&amp;gt;, with the full config options available [https://www.chartjs.org/docs/latest/configuration/tooltip.html here].&lt;br /&gt;
&lt;br /&gt;
;Change labels colours of datasets&lt;br /&gt;
Dataset options are found under key &amp;lt;code&amp;gt;data.datasets[#]&amp;lt;/code&amp;gt;, and can (and should) be different per dataset. Labels are set with the label field. You can set the backgroundColor and borderColor options separately, and you may need to set showLine=true and/or fill=false.&lt;br /&gt;
&lt;br /&gt;
Be careful when choosing colours so that they work in both light and dark mode adequetely (use the pre-provided colour schemes).&lt;br /&gt;
&lt;br /&gt;
If you have a number of lines, you should considerhaving some of them be [https://www.chartjs.org/docs/latest/charts/line.html#line-styling dashed lines] (borderDash option).&lt;br /&gt;
&lt;br /&gt;
===Helper functions===&lt;br /&gt;
[[Module:Chart data]] provides several helper functions for creating charts.&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;code&amp;gt;convertToXYFormat(y, [x])&amp;lt;/code&amp;gt;&lt;br /&gt;
Provide this function with either just an array of y-values, or with both an array of y- and x-values. It will construct the [https://www.chartjs.org/docs/latest/charts/line.html#point Point-style] data array for use with line and scatter charts.&lt;br /&gt;
&lt;br /&gt;
If no x-value array is provided, the y-values will be paired with their index (beginning at 1).&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;code&amp;gt;generateXYFromFunc(func, start_x, end_x, [step])&amp;lt;/code&amp;gt;&lt;br /&gt;
This will generate Point-style data using the provided function, where y=func(x). Data is generated for x from start_x to end_x by step (default step is 1 if not specified).&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;code&amp;gt;jagexInterpolation(low_chance, high_chance, start_level, end_level)&amp;lt;/code&amp;gt;&lt;br /&gt;
This will interpolate values for skilling chances using the same function as Jagex, using the specified low_chance and high_chance, from start_level to end_level by step size 1. This is a specialised version of generateXYFromFunc.&lt;br /&gt;
&lt;br /&gt;
;Colours&lt;br /&gt;
5 preset colours are specified by the &amp;lt;code&amp;gt;colors&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;colours&amp;lt;/code&amp;gt;) array, which each element has a bg and bd key specified which are suggested colours to use for datasets. If you need more than 5 datasets, consider using dashed lines, changing point style, or similar (or multiple things). See [[Module:Chart data/test chart]] for an example config which generates this chart:&lt;br /&gt;
&lt;br /&gt;
{{Chart data|Chart data/test chart|width=40vw|height=40vh}}&lt;br /&gt;
&lt;br /&gt;
If you are using a bar chart or similar and you need more colours, consider using one of the following to get some new colours for datasets. Make sure to preview your chart in both light and dark mode to make sure it is still viewable in both.&lt;br /&gt;
&lt;br /&gt;
* http://mkweb.bcgsc.ca/brewer/&lt;br /&gt;
* https://carto.com/carto-colors/&lt;br /&gt;
* https://github.com/EmilHvitfeldt/r-color-palettes&lt;br /&gt;
* https://learnui.design/tools/data-color-picker.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;[[Category:Formatting templates]][[Category:Mathematical templates]][[Category:Calculator templates]]&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>