Module:Chart data

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Chart data/doc. [edit] [history] [purge]
Module:Chart data's function main is invoked by Template:Chart data.
Module:Chart data requires Module:Array.
Module:Chart data requires Module:Chart data/Colors.
Module:Chart data requires Module:LibraryUtil.
Module:Chart data requires Module:Paramtest.
Module:Chart data requires Module:Rgba.
Module:Chart data is required by .
Function list
L 23 — default
L 33 — defaultOptions
L 34 — _setOptions
L 47 — stripNonChartJsVariables
L 60 — _strip
L 75 — stripInvalidValues
L 110 — chart.main
L 116 — chart._main
L 167 — chart.convertToXYFormat
L 186 — chart.generateXYFromFunc
L 207 — chart.jagexInterpolation
L 213 — interpolate
L 222 — chart.newChart
L 336 — chart:addDataSets
L 353 — chart:addDataLabels
L 372 — chart:setDimensions
L 448 — chart:setTitle
L 466 — chart:setXLabel
L 488 — chart:setYLabel
L 512 — chart:setXLimits
L 539 — chart:setYLimits
L 564 — chart:setYFormat
L 583 — chart:setXFormat
L 604 — chart:setRadialLimits
L 627 — chart:setXAxisType
L 651 — chart:setYAxisType
L 675 — chart:showLegend
L 690 — chart:setTooltipFormat
L 705 — chart:setDatasetsPerGroup
L 717 — chart:flipXY
L 746 — chart:setOptions
L 750 — _setOptions
L 766 — chart:finish
L 852 — chart:tostring
L 858 — chart:debug
L 879 — chart:newDataSet
L 908 — dataSet:addData
L 921 — dataSet:addDataPoint
L 931 — dataSet:setOptions
L 935 — _setOptions
L 951 — dataSet:done

Helps create the json to generate charts using Chart.js v3 through MediaWiki:Gadget-Charts-core.js.

This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
_main( args )table/chartTurns a table/chart object into a json string.
convertToXYFormat( ys, [xs|{}] )table, tableConverts the ys array into an array of {x = n, y = y[n]} tables. If xs is already partially filled it will use {x = x[n], y = y[n]} until all values in xs are used, then it will use {x = n, y = y[n]} again for the remaining values in ys.
generateXYFromFunc( func, start_x, end_x, [step|1] )function, number, number, numberReturns an arry of {x = n, y = fun(n)} tables where n ranges from start_x to end_x in step increments. Be careful when using decimal step values as floating point error can cause the generator to stop one element too soon.
jagexInterpolation( low_chance, high_chance, start_level, end_level )number, number, number, number
newChart( [options] )tableReturns a new chart object. options is a table with options in the Chart.js format. Most options will be set automatically or will be set later with other functions if not already defined. Usually all you need to define here is the chart type e.g. newChart{ type = 'scatter' }. Check the modules documentation for more info.
chart:addDataSets( ... )table/dataSet objectAppends all given data sets to the chart.data.datasets table.
chart:addDataLabels( labels )tableAppends all items in labels to the chart.data.labels table.
chart:setDimensions( width, [height|width], [minWidth|400], [minHeight|400], [resizable|true] )number/string, number/string, number/string, number/string, booleanSets the dimensions of the chart. If a number is given to width, height, minWidth and minHeight it will be assumed you meant pixels. You can also use strings like 100% to fill the available space, 60vw/60vh to dynamically scale the simensions to the viewport size (i.e. 60vw = 60% of browser's window width). If resizable is true, the chart can be dragged by the lower right corner to change its size. If this function is not called the default values are width = 60vw, height = 60vh, minWidth = 400px, minHeight = 400px and resizable = true.
chart:setTitle( [text|nil], [position|'top'] )string, stringSets the label title of the chart. A value of nil will remove the current title.
chart:setXLabel( [label|nil] )stringSets the label for the x axis. Only works on chart types 'line', 'bar', 'bubble' and 'scatter'. If used without arguments it will remove the current label.
chart:setYLabel( [label|nil] )stringSets the label for the y axis. Only works on chart types 'line', 'bar', 'bubble' and 'scatter'. If used without arguments it will remove the current label.
chart:setXLimits( [min|nil], [max|nil], [step|nil] )number, number, numberSets the start, stop and step size of the x axis. Any argument with a value of nil will remove that setting. Only works on chart types 'bubble' and 'scatter'.
chart:setYLimits( [min|nil], [max|nil], [step|nil] )number, number, numberSets the start, stop and step size of the y axis. Any argument with a value of nil will remove that setting. Only works on chart types 'line', 'bar', 'bubble' and 'scatter'.
chart:setRadialLimits( [min|nil], [max|nil], [step|nil] )number, number, numberSets the start, stop and step size of the r axis on polar plots. Any argument with a value of nil will remove that setting. Only works on chart types 'radar' and 'polarArea'.
chart:setXAxisType( [type|nil] )stringSets the axis type. Supported values are 'linear', 'logarithmic', 'category' and 'time'. If called without arguments it will reset back to the default value 'linear'. Only works on chart types 'bar', 'bubble', 'line' and 'scatter'.
chart:setYAxisType( [type|nil] )stringSame as chart:setXAxisType() but for the y axis. Only works on chart types 'bar', 'bubble', 'line' and 'scatter'.
chart:showLegend( val )booleanHides the legend if val is false.
chart:setOptions( options )tableSets options using Chart.js format but makes sure you only change the given settings and not accidentally delete already existing settings. i.e. using chart:setOptions{ scales = {x = {max = 100}} } while {scales = {x = {min = 0}}} already exists will result in {scales = {x = {min = 0, max = 100}}}.
chart:flipXY()N/ATurn the bar chart into a horizontal one. Only has an effect on bar charts.
chart:debug()N/APretty prints the internal structure since you can't use mw.logObject to do so.
chart:newDataSet( [options] )tableReturns a new dataSet object which is also automatically added to the chart datasets table.
dataSet:addData( data )tableAppends the values of data to the already existing data stored in the dataSet.data array. Using dataset.data = data will overwrite any stored data.
dataSet:addDataPoint( data )number/tableAppend a single value to the dataSet.data array. Same as table.insert( dataSet.data, data ).
dataSet:setOptions( options )tableSets options using Chart.js format.
dataSet:done()N/AReturns the parent chart object again.
Example:
local p = {}
local chart = require( 'Module:Chart data' )

-- This chart can then be added to a page using {{Chart data|<module name>|pie}} or {{#Invoke:<module name>|pie}}
-- It could also further be used be another module/function
function p.pie()
    local plot = chart.newChart{ type = 'pie' }
    plot:setDimensions( '40vw', nil, 400, nil, true ) -- Pie chart is always square
    plot.colorPalette = chart.colorPalettes.green
    local labels = {}
    local set = plot:newDataSet()

    for i = 1, 6 do
        set:addDataPoint( math.floor( math.sqrt( i ) * 10 + 0.5 ) / 10 )
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end

return p

-------------------------------------------------------------
local p = {}
local chart = require( 'Module:Chart data' )

function p.bar()
    local plot = chart.newChart{ type = 'bar' }
        :setDimensions( '40%', 600, 400, 400, true ) -- Settings can be chained
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )

    for i = 1, 2 do
        local set = plot:newDataSet()
        for j = 1, 6 do
            set:addDataPoint( math.sqrt( i*j ) )
        end
        set.label = 'Set ' .. i

        if i == 1 then
            set.color = chart.colorPalettes.green[3]
        else
            set.color = chart.colorPalettes.orange[3]
        end
    end

    local labels = {}

    for i = 1, 6 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return 'Some header text' .. plot -- Charts are automatically converted to strings when appended to another string
end

return p

Usage

To create a chart we need to create JSON in a format described by chart.js. To make this a bit easier we can write a lua table instead which is then converted to a JSON using chart._main(). An example of this is Module:Chart data/xp chart, which can then be displayed on a page using {{Chart data|Chart data/xp chart|height=40vh|width=40vw}} resulting in:

{"type":"scatter","data":{"datasets":[{"data":[{"y":0,"x":1},{"y":83,"x":2},{"y":174,"x":3},{"y":276,"x":4},{"y":388,"x":5},{"y":512,"x":6},{"y":650,"x":7},{"y":801,"x":8},{"y":969,"x":9},{"y":1154,"x":10},{"y":1358,"x":11},{"y":1584,"x":12},{"y":1833,"x":13},{"y":2107,"x":14},{"y":2411,"x":15},{"y":2746,"x":16},{"y":3115,"x":17},{"y":3523,"x":18},{"y":3973,"x":19},{"y":4470,"x":20},{"y":5018,"x":21},{"y":5624,"x":22},{"y":6291,"x":23},{"y":7028,"x":24},{"y":7842,"x":25},{"y":8740,"x":26},{"y":9730,"x":27},{"y":10824,"x":28},{"y":12031,"x":29},{"y":13363,"x":30},{"y":14833,"x":31},{"y":16456,"x":32},{"y":18247,"x":33},{"y":20224,"x":34},{"y":22406,"x":35},{"y":24815,"x":36},{"y":27473,"x":37},{"y":30408,"x":38},{"y":33648,"x":39},{"y":37224,"x":40},{"y":41171,"x":41},{"y":45529,"x":42},{"y":50339,"x":43},{"y":55649,"x":44},{"y":61512,"x":45},{"y":67983,"x":46},{"y":75127,"x":47},{"y":83014,"x":48},{"y":91721,"x":49},{"y":101333,"x":50},{"y":111945,"x":51},{"y":123660,"x":52},{"y":136594,"x":53},{"y":150872,"x":54},{"y":166636,"x":55},{"y":184040,"x":56},{"y":203254,"x":57},{"y":224466,"x":58},{"y":247886,"x":59},{"y":273742,"x":60},{"y":302288,"x":61},{"y":333804,"x":62},{"y":368599,"x":63},{"y":407015,"x":64},{"y":449428,"x":65},{"y":496254,"x":66},{"y":547953,"x":67},{"y":605032,"x":68},{"y":668051,"x":69},{"y":737627,"x":70},{"y":814445,"x":71},{"y":899257,"x":72},{"y":992895,"x":73},{"y":1096278,"x":74},{"y":1210421,"x":75},{"y":1336443,"x":76},{"y":1475581,"x":77},{"y":1629200,"x":78},{"y":1798808,"x":79},{"y":1986068,"x":80},{"y":2192818,"x":81},{"y":2421087,"x":82},{"y":2673114,"x":83},{"y":2951373,"x":84},{"y":3258594,"x":85},{"y":3597792,"x":86},{"y":3972294,"x":87},{"y":4385776,"x":88},{"y":4842295,"x":89},{"y":5346332,"x":90},{"y":5902831,"x":91},{"y":6517253,"x":92},{"y":7195629,"x":93},{"y":7944614,"x":94},{"y":8771558,"x":95},{"y":9684577,"x":96},{"y":10692629,"x":97},{"y":11805606,"x":98},{"y":13034431,"x":99},{"y":14391160,"x":100},{"y":15889109,"x":101},{"y":17542976,"x":102},{"y":19368992,"x":103},{"y":21385073,"x":104},{"y":23611006,"x":105},{"y":26068632,"x":106},{"y":28782069,"x":107},{"y":31777943,"x":108},{"y":35085654,"x":109},{"y":38737661,"x":110},{"y":42769801,"x":111},{"y":47221641,"x":112},{"y":52136869,"x":113},{"y":57563718,"x":114},{"y":63555443,"x":115},{"y":70170840,"x":116},{"y":77474828,"x":117},{"y":85539082,"x":118},{"y":94442737,"x":119},{"y":104273167,"x":120},{"y":115126838,"x":121},{"y":127110260,"x":122},{"y":140341028,"x":123},{"y":154948977,"x":124},{"y":171077457,"x":125},{"y":188884740,"x":126},{"y":208545572,"x":127},{"y":230252886,"x":128},{"y":254219702,"x":129},{"y":280681209,"x":130},{"y":309897078,"x":131},{"y":342154009,"x":132},{"y":377768545,"x":133},{"y":417090179,"x":134},{"y":460504778,"x":135},{"y":508438379,"x":136},{"y":561361362,"x":137},{"y":619793069,"x":138},{"y":684306901,"x":139},{"y":755535943,"x":140}],"label":"Standard skill","borderColor":"rgba(253,127,111,1)","showLine":true,"backgroundColor":"rgba(253,127,111,0.2)","fill":false},{"data":[{"y":0,"x":1},{"y":830,"x":2},{"y":1861,"x":3},{"y":2902,"x":4},{"y":3980,"x":5},{"y":5126,"x":6},{"y":6380,"x":7},{"y":7787,"x":8},{"y":9400,"x":9},{"y":11275,"x":10},{"y":13605,"x":11},{"y":16372,"x":12},{"y":19656,"x":13},{"y":23546,"x":14},{"y":28134,"x":15},{"y":33520,"x":16},{"y":39809,"x":17},{"y":47109,"x":18},{"y":55535,"x":19},{"y":65209,"x":20},{"y":77190,"x":21},{"y":90811,"x":22},{"y":106221,"x":23},{"y":123573,"x":24},{"y":143025,"x":25},{"y":164742,"x":26},{"y":188893,"x":27},{"y":215651,"x":28},{"y":245196,"x":29},{"y":277713,"x":30},{"y":316311,"x":31},{"y":358547,"x":32},{"y":404634,"x":33},{"y":454796,"x":34},{"y":509259,"x":35},{"y":568254,"x":36},{"y":632019,"x":37},{"y":700797,"x":38},{"y":774834,"x":39},{"y":854383,"x":40},{"y":946227,"x":41},{"y":1044569,"x":42},{"y":1149696,"x":43},{"y":1261903,"x":44},{"y":1381488,"x":45},{"y":1508756,"x":46},{"y":1644015,"x":47},{"y":1787581,"x":48},{"y":1939773,"x":49},{"y":2100917,"x":50},{"y":2283490,"x":51},{"y":2476369,"x":52},{"y":2679917,"x":53},{"y":2894505,"x":54},{"y":3120508,"x":55},{"y":3358307,"x":56},{"y":3608290,"x":57},{"y":3870846,"x":58},{"y":4146374,"x":59},{"y":4435275,"x":60},{"y":4758122,"x":61},{"y":5096111,"x":62},{"y":5449685,"x":63},{"y":5819299,"x":64},{"y":6205407,"x":65},{"y":6608473,"x":66},{"y":7028964,"x":67},{"y":7467354,"x":68},{"y":7924122,"x":69},{"y":8399751,"x":70},{"y":8925664,"x":71},{"y":9472665,"x":72},{"y":10041285,"x":73},{"y":10632061,"x":74},{"y":11245538,"x":75},{"y":11882262,"x":76},{"y":12542789,"x":77},{"y":13227679,"x":78},{"y":13937496,"x":79},{"y":14672812,"x":80},{"y":15478994,"x":81},{"y":16313404,"x":82},{"y":17176661,"x":83},{"y":18069395,"x":84},{"y":18992239,"x":85},{"y":19945833,"x":86},{"y":20930821,"x":87},{"y":21947856,"x":88},{"y":22997593,"x":89},{"y":24080695,"x":90},{"y":25259906,"x":91},{"y":26475754,"x":92},{"y":27728955,"x":93},{"y":29020233,"x":94},{"y":30350318,"x":95},{"y":31719944,"x":96},{"y":33129852,"x":97},{"y":34580790,"x":98},{"y":36073511,"x":99},{"y":37608773,"x":100},{"y":39270442,"x":101},{"y":40978509,"x":102},{"y":42733789,"x":103},{"y":44537107,"x":104},{"y":46389292,"x":105},{"y":48291180,"x":106},{"y":50243611,"x":107},{"y":52247435,"x":108},{"y":54303504,"x":109},{"y":56412678,"x":110},{"y":58575824,"x":111},{"y":60793812,"x":112},{"y":63067521,"x":113},{"y":65397835,"x":114},{"y":67785643,"x":115},{"y":70231841,"x":116},{"y":72737330,"x":117},{"y":75303019,"x":118},{"y":77929820,"x":119},{"y":80618654,"x":120},{"y":83370445,"x":121},{"y":86186124,"x":122},{"y":89066630,"x":123},{"y":92012904,"x":124},{"y":95025896,"x":125},{"y":98106559,"x":126},{"y":101255855,"x":127},{"y":104474750,"x":128},{"y":107764216,"x":129},{"y":111125230,"x":130},{"y":114558777,"x":131},{"y":118065845,"x":132},{"y":121647430,"x":133},{"y":125304532,"x":134},{"y":129038159,"x":135},{"y":132849323,"x":136},{"y":136739041,"x":137},{"y":140708338,"x":138},{"y":144758242,"x":139},{"y":148889790,"x":140},{"y":153104021,"x":141},{"y":157401983,"x":142},{"y":161784728,"x":143},{"y":166253312,"x":144},{"y":170808801,"x":145},{"y":175452262,"x":146},{"y":180184770,"x":147},{"y":185007406,"x":148},{"y":189921255,"x":149},{"y":194927409,"x":150}],"pointStyle":"crossRot","pointRadius":6,"label":"Elite skill","borderColor":"rgba(126,176,213,1)","showLine":true,"backgroundColor":"rgba(126,176,213,0.2)","fill":false}]},"options":{"maintainAspectRatio":false,"scales":{"y":{"scaleLabel":{"display":true,"labelString":"Experience"}},"x":{"scaleLabel":{"display":true,"labelString":"Level"}}},"tooltips":{"mode":"x","intersect":false,"position":"nearest"}}}

To make the construction of this table a bit easier, the chart class is provided which internally has the extact same structure as if we manually created the table. The chart class just sets a bunch of default settings based on what chart type you are creating; it also makes it a lot easier to deal with the colors of your data and provides a bunch of functions to easily set axis labels, axis start and stop values, axis type, etc.

Create new chart object

local chart = require( 'Module:Chart data' )

local plot = chart.newChart{ type = 'scatter' } -- If no type is given it will default to 'scatter'
plot.fill = true -- Show background, exact behaviour depends on chart type

-- The above two lines are equivalent to
local plot = chart.newChart{ type = 'scatter', fill = true }

Chaining functions

local plot = chart.newChart()
    :setDimensions( '40vh', '50vw', '400px', '400px', true )
    :setTitle( 'My title' )
    
-- Or
local plot = chart.newChart()
plot:setDimensions( '40vh', '50vw', '400px', '400px', true )
plot:setTitle( 'My title' )

Datasets

local plot = chart.newChart()

local dataSet = plot:newDataSet() -- This data set is already added to plot so you don't need to use plot:addDataSets( dataSet )
dataSet.data = chart.generateXYFromFunc( ... )
dataSet:addDataPoint( { x=5, y=10} ) -- Append another data point to the already existing data
dataSet:setOptions{ fill = true }

-- Or
plot:newDataSet{ data = chart.generateXYFromFunc( ... ), fill = true }
    :addDataPoint( { x=5, y=10 } )

You can also add datasets that you created somewhere else. The downside is that you then can't use addData/addDataPoint/setOptions functions on that set.

local set = chart.generateXYFromFunc( ... )

plot:addDataSets( set )

Datasets can also chain functions

local plot = chart.newChart()
    :newDataSet{ data = myDataSet }
        :addDataPoint( { x=5, y=10 } )
    :done()
    :newDataSet{ data = anotherDataSet }:done()

Color Palettes

chart.colorPalettes has a few pre-defined color Palettes. These Palettes are made up of Module:Rgba objects. Colors will default to black if there are more datasets than colors in the palette.

You can set your prefered Palette for your chart with myChart.colorPalette = chart.colorPalettes.blue, in case of chart type bar of horizontalbar your can also set it per data set myDataSet.colorPalette = chart.colorPalettes.orange or if you want all bars of a given set to be the same color myDataSet.color = chart.colorPalettes.orange[3].

It is possible to define your own color Palette as an array of Module:Rgba objects.

The chart class has the following color opions:

  • backgroundAlpha - sets the rgba:fade() value for background colors.
  • hoverLightenValue - sets the rgba:lighten() value for when you hover over a data point.
  • hoverAlpha - sets the rgba:fade() value for when you hover over a data point.
  • hoverSaturateValue - sets the rgba:saturate() value for when you hover over a data point.

Their default value depend on the cart type but you can manually set them using:

chart:setOptions{
    backgroundAlpha = <number>,
    hoverLightenValue = <number>,
    hoverAlpha = <number>,
    hoverSaturateValue = <number>
}
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Qualitative","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(151,198,222,1)","borderColor":"rgba(166,206,227,1)","hoverBackgroundColor":"rgba(151,198,222,0.5)","backgroundColor":"rgba(166,206,227,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(29,114,171,1)","borderColor":"rgba(31,120,180,1)","hoverBackgroundColor":"rgba(29,114,171,0.5)","backgroundColor":"rgba(31,120,180,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(169,219,124,1)","borderColor":"rgba(178,223,138,1)","hoverBackgroundColor":"rgba(169,219,124,0.5)","backgroundColor":"rgba(178,223,138,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(48,152,42,1)","borderColor":"rgba(51,160,44,1)","hoverBackgroundColor":"rgba(48,152,42,0.5)","backgroundColor":"rgba(51,160,44,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(250,135,134,1)","borderColor":"rgba(251,154,153,1)","hoverBackgroundColor":"rgba(250,135,134,0.5)","backgroundColor":"rgba(251,154,153,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(216,25,27,1)","borderColor":"rgba(227,26,28,1)","hoverBackgroundColor":"rgba(216,25,27,0.5)","backgroundColor":"rgba(227,26,28,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(253,183,93,1)","borderColor":"rgba(253,191,111,1)","hoverBackgroundColor":"rgba(253,183,93,0.5)","backgroundColor":"rgba(253,191,111,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 8","showLine":true,"data":[{"y":0,"x":0},{"y":8,"x":1},{"y":32,"x":2},{"y":72,"x":3},{"y":128,"x":4},{"y":200,"x":5},{"y":288,"x":6},{"y":392,"x":7},{"y":512,"x":8},{"y":648,"x":9},{"y":800,"x":10},{"y":968,"x":11},{"y":1152,"x":12},{"y":1352,"x":13},{"y":1568,"x":14},{"y":1800,"x":15},{"y":2048,"x":16},{"y":2312,"x":17},{"y":2592,"x":18},{"y":2888,"x":19},{"y":3200,"x":20},{"y":3528,"x":21},{"y":3872,"x":22},{"y":4232,"x":23},{"y":4608,"x":24},{"y":5000,"x":25},{"y":5408,"x":26},{"y":5832,"x":27},{"y":6272,"x":28},{"y":6728,"x":29},{"y":7200,"x":30},{"y":7688,"x":31},{"y":8192,"x":32},{"y":8712,"x":33},{"y":9248,"x":34},{"y":9800,"x":35},{"y":10368,"x":36},{"y":10952,"x":37},{"y":11552,"x":38},{"y":12168,"x":39},{"y":12800,"x":40},{"y":13448,"x":41},{"y":14112,"x":42},{"y":14792,"x":43},{"y":15488,"x":44},{"y":16200,"x":45},{"y":16928,"x":46},{"y":17672,"x":47},{"y":18432,"x":48},{"y":19208,"x":49},{"y":20000,"x":50}],"hoverBorderColor":"rgba(242,121,0,1)","borderColor":"rgba(255,127,0,1)","hoverBackgroundColor":"rgba(242,121,0,0.5)","backgroundColor":"rgba(255,127,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 9","showLine":true,"data":[{"y":0,"x":0},{"y":9,"x":1},{"y":36,"x":2},{"y":81,"x":3},{"y":144,"x":4},{"y":225,"x":5},{"y":324,"x":6},{"y":441,"x":7},{"y":576,"x":8},{"y":729,"x":9},{"y":900,"x":10},{"y":1089,"x":11},{"y":1296,"x":12},{"y":1521,"x":13},{"y":1764,"x":14},{"y":2025,"x":15},{"y":2304,"x":16},{"y":2601,"x":17},{"y":2916,"x":18},{"y":3249,"x":19},{"y":3600,"x":20},{"y":3969,"x":21},{"y":4356,"x":22},{"y":4761,"x":23},{"y":5184,"x":24},{"y":5625,"x":25},{"y":6084,"x":26},{"y":6561,"x":27},{"y":7056,"x":28},{"y":7569,"x":29},{"y":8100,"x":30},{"y":8649,"x":31},{"y":9216,"x":32},{"y":9801,"x":33},{"y":10404,"x":34},{"y":11025,"x":35},{"y":11664,"x":36},{"y":12321,"x":37},{"y":12996,"x":38},{"y":13689,"x":39},{"y":14400,"x":40},{"y":15129,"x":41},{"y":15876,"x":42},{"y":16641,"x":43},{"y":17424,"x":44},{"y":18225,"x":45},{"y":19044,"x":46},{"y":19881,"x":47},{"y":20736,"x":48},{"y":21609,"x":49},{"y":22500,"x":50}],"hoverBorderColor":"rgba(193,165,207,1)","borderColor":"rgba(202,178,214,1)","hoverBackgroundColor":"rgba(193,165,207,0.5)","backgroundColor":"rgba(202,178,214,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 10","showLine":true,"data":[{"y":0,"x":0},{"y":10,"x":1},{"y":40,"x":2},{"y":90,"x":3},{"y":160,"x":4},{"y":250,"x":5},{"y":360,"x":6},{"y":490,"x":7},{"y":640,"x":8},{"y":810,"x":9},{"y":1000,"x":10},{"y":1210,"x":11},{"y":1440,"x":12},{"y":1690,"x":13},{"y":1960,"x":14},{"y":2250,"x":15},{"y":2560,"x":16},{"y":2890,"x":17},{"y":3240,"x":18},{"y":3610,"x":19},{"y":4000,"x":20},{"y":4410,"x":21},{"y":4840,"x":22},{"y":5290,"x":23},{"y":5760,"x":24},{"y":6250,"x":25},{"y":6760,"x":26},{"y":7290,"x":27},{"y":7840,"x":28},{"y":8410,"x":29},{"y":9000,"x":30},{"y":9610,"x":31},{"y":10240,"x":32},{"y":10890,"x":33},{"y":11560,"x":34},{"y":12250,"x":35},{"y":12960,"x":36},{"y":13690,"x":37},{"y":14440,"x":38},{"y":15210,"x":39},{"y":16000,"x":40},{"y":16810,"x":41},{"y":17640,"x":42},{"y":18490,"x":43},{"y":19360,"x":44},{"y":20250,"x":45},{"y":21160,"x":46},{"y":22090,"x":47},{"y":23040,"x":48},{"y":24010,"x":49},{"y":25000,"x":50}],"hoverBorderColor":"rgba(101,58,146,1)","borderColor":"rgba(106,61,154,1)","hoverBackgroundColor":"rgba(101,58,146,0.5)","backgroundColor":"rgba(106,61,154,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorQualitative}}

function p.colorQualitative()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Qualitative' )
    plot.options.colorPalette = chart.colorPalettes.qualitative

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Blue","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(194,195,222,1)","borderColor":"rgba(208,209,230,1)","hoverBackgroundColor":"rgba(194,195,222,0.5)","backgroundColor":"rgba(208,209,230,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(152,179,213,1)","borderColor":"rgba(166,189,219,1)","hoverBackgroundColor":"rgba(152,179,213,0.5)","backgroundColor":"rgba(166,189,219,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(91,162,203,1)","borderColor":"rgba(103,169,207,1)","hoverBackgroundColor":"rgba(91,162,203,0.5)","backgroundColor":"rgba(103,169,207,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(51,137,182,1)","borderColor":"rgba(54,144,192,1)","hoverBackgroundColor":"rgba(51,137,182,0.5)","backgroundColor":"rgba(54,144,192,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(2,123,131,1)","borderColor":"rgba(2,129,138,1)","hoverBackgroundColor":"rgba(2,123,131,0.5)","backgroundColor":"rgba(2,129,138,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(1,103,85,1)","borderColor":"rgba(1,108,89,1)","hoverBackgroundColor":"rgba(1,103,85,0.5)","backgroundColor":"rgba(1,108,89,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(1,67,51,1)","borderColor":"rgba(1,70,54,1)","hoverBackgroundColor":"rgba(1,67,51,0.5)","backgroundColor":"rgba(1,70,54,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorBlue}}

function p.colorBlue()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Blue' )
    plot.options.colorPalette = chart.colorPalettes.blue

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Green","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(210,237,146,1)","borderColor":"rgba(217,240,163,1)","hoverBackgroundColor":"rgba(210,237,146,0.5)","backgroundColor":"rgba(217,240,163,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(163,217,128,1)","borderColor":"rgba(173,221,142,1)","hoverBackgroundColor":"rgba(163,217,128,0.5)","backgroundColor":"rgba(173,221,142,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(109,193,110,1)","borderColor":"rgba(120,198,121,1)","hoverBackgroundColor":"rgba(109,193,110,0.5)","backgroundColor":"rgba(120,198,121,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(62,162,88,1)","borderColor":"rgba(65,171,93,1)","hoverBackgroundColor":"rgba(62,162,88,0.5)","backgroundColor":"rgba(65,171,93,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(33,125,64,1)","borderColor":"rgba(35,132,67,1)","hoverBackgroundColor":"rgba(33,125,64,0.5)","backgroundColor":"rgba(35,132,67,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(0,99,52,1)","borderColor":"rgba(0,104,55,1)","hoverBackgroundColor":"rgba(0,99,52,0.5)","backgroundColor":"rgba(0,104,55,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(0,66,40,1)","borderColor":"rgba(0,69,42,1)","hoverBackgroundColor":"rgba(0,66,40,0.5)","backgroundColor":"rgba(0,69,42,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorGreen}}

function p.colorGreen()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Green' )
    plot.options.colorPalette = chart.colorPalettes.green

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"BlueGreen","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(188,230,222,1)","borderColor":"rgba(204,236,230,1)","hoverBackgroundColor":"rgba(188,230,222,0.5)","backgroundColor":"rgba(204,236,230,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(140,211,194,1)","borderColor":"rgba(153,216,201,1)","hoverBackgroundColor":"rgba(140,211,194,0.5)","backgroundColor":"rgba(153,216,201,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(91,190,158,1)","borderColor":"rgba(102,194,164,1)","hoverBackgroundColor":"rgba(91,190,158,0.5)","backgroundColor":"rgba(102,194,164,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(62,165,112,1)","borderColor":"rgba(65,174,118,1)","hoverBackgroundColor":"rgba(62,165,112,0.5)","backgroundColor":"rgba(65,174,118,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(33,132,66,1)","borderColor":"rgba(35,139,69,1)","hoverBackgroundColor":"rgba(33,132,66,0.5)","backgroundColor":"rgba(35,139,69,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(0,104,42,1)","borderColor":"rgba(0,109,44,1)","hoverBackgroundColor":"rgba(0,104,42,0.5)","backgroundColor":"rgba(0,109,44,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(0,65,26,1)","borderColor":"rgba(0,68,27,1)","hoverBackgroundColor":"rgba(0,65,26,0.5)","backgroundColor":"rgba(0,68,27,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorBlueGreen}}

function p.colorBlueGreen()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'BlueGreen' )
    plot.options.colorPalette = chart.colorPalettes.blueGreen

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Orange","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(254,222,125,1)","borderColor":"rgba(254,227,145,1)","hoverBackgroundColor":"rgba(254,222,125,0.5)","backgroundColor":"rgba(254,227,145,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(254,190,62,1)","borderColor":"rgba(254,196,79,1)","hoverBackgroundColor":"rgba(254,190,62,0.5)","backgroundColor":"rgba(254,196,79,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(254,146,26,1)","borderColor":"rgba(254,153,41,1)","hoverBackgroundColor":"rgba(254,146,26,0.5)","backgroundColor":"rgba(254,153,41,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(225,106,18,1)","borderColor":"rgba(236,112,20,1)","hoverBackgroundColor":"rgba(225,106,18,0.5)","backgroundColor":"rgba(236,112,20,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(194,72,2,1)","borderColor":"rgba(204,76,2,1)","hoverBackgroundColor":"rgba(194,72,2,0.5)","backgroundColor":"rgba(204,76,2,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(145,49,4,1)","borderColor":"rgba(153,52,4,1)","hoverBackgroundColor":"rgba(145,49,4,0.5)","backgroundColor":"rgba(153,52,4,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(97,35,6,1)","borderColor":"rgba(102,37,6,1)","hoverBackgroundColor":"rgba(97,35,6,0.5)","backgroundColor":"rgba(102,37,6,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorOrange}}

function p.colorOrange()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Orange' )
    plot.options.colorPalette = chart.colorPalettes.orange

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"legend":{"display":false},"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Color overflow","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(254,222,125,1)","borderColor":"rgba(254,227,145,1)","hoverBackgroundColor":"rgba(254,222,125,0.5)","backgroundColor":"rgba(254,227,145,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(254,190,62,1)","borderColor":"rgba(254,196,79,1)","hoverBackgroundColor":"rgba(254,190,62,0.5)","backgroundColor":"rgba(254,196,79,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(254,146,26,1)","borderColor":"rgba(254,153,41,1)","hoverBackgroundColor":"rgba(254,146,26,0.5)","backgroundColor":"rgba(254,153,41,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(225,106,18,1)","borderColor":"rgba(236,112,20,1)","hoverBackgroundColor":"rgba(225,106,18,0.5)","backgroundColor":"rgba(236,112,20,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":5,"x":1},{"y":20,"x":2},{"y":45,"x":3},{"y":80,"x":4},{"y":125,"x":5},{"y":180,"x":6},{"y":245,"x":7},{"y":320,"x":8},{"y":405,"x":9},{"y":500,"x":10},{"y":605,"x":11},{"y":720,"x":12},{"y":845,"x":13},{"y":980,"x":14},{"y":1125,"x":15},{"y":1280,"x":16},{"y":1445,"x":17},{"y":1620,"x":18},{"y":1805,"x":19},{"y":2000,"x":20},{"y":2205,"x":21},{"y":2420,"x":22},{"y":2645,"x":23},{"y":2880,"x":24},{"y":3125,"x":25},{"y":3380,"x":26},{"y":3645,"x":27},{"y":3920,"x":28},{"y":4205,"x":29},{"y":4500,"x":30},{"y":4805,"x":31},{"y":5120,"x":32},{"y":5445,"x":33},{"y":5780,"x":34},{"y":6125,"x":35},{"y":6480,"x":36},{"y":6845,"x":37},{"y":7220,"x":38},{"y":7605,"x":39},{"y":8000,"x":40},{"y":8405,"x":41},{"y":8820,"x":42},{"y":9245,"x":43},{"y":9680,"x":44},{"y":10125,"x":45},{"y":10580,"x":46},{"y":11045,"x":47},{"y":11520,"x":48},{"y":12005,"x":49},{"y":12500,"x":50}],"hoverBorderColor":"rgba(194,72,2,1)","borderColor":"rgba(204,76,2,1)","hoverBackgroundColor":"rgba(194,72,2,0.5)","backgroundColor":"rgba(204,76,2,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 6","showLine":true,"data":[{"y":0,"x":0},{"y":6,"x":1},{"y":24,"x":2},{"y":54,"x":3},{"y":96,"x":4},{"y":150,"x":5},{"y":216,"x":6},{"y":294,"x":7},{"y":384,"x":8},{"y":486,"x":9},{"y":600,"x":10},{"y":726,"x":11},{"y":864,"x":12},{"y":1014,"x":13},{"y":1176,"x":14},{"y":1350,"x":15},{"y":1536,"x":16},{"y":1734,"x":17},{"y":1944,"x":18},{"y":2166,"x":19},{"y":2400,"x":20},{"y":2646,"x":21},{"y":2904,"x":22},{"y":3174,"x":23},{"y":3456,"x":24},{"y":3750,"x":25},{"y":4056,"x":26},{"y":4374,"x":27},{"y":4704,"x":28},{"y":5046,"x":29},{"y":5400,"x":30},{"y":5766,"x":31},{"y":6144,"x":32},{"y":6534,"x":33},{"y":6936,"x":34},{"y":7350,"x":35},{"y":7776,"x":36},{"y":8214,"x":37},{"y":8664,"x":38},{"y":9126,"x":39},{"y":9600,"x":40},{"y":10086,"x":41},{"y":10584,"x":42},{"y":11094,"x":43},{"y":11616,"x":44},{"y":12150,"x":45},{"y":12696,"x":46},{"y":13254,"x":47},{"y":13824,"x":48},{"y":14406,"x":49},{"y":15000,"x":50}],"hoverBorderColor":"rgba(145,49,4,1)","borderColor":"rgba(153,52,4,1)","hoverBackgroundColor":"rgba(145,49,4,0.5)","backgroundColor":"rgba(153,52,4,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 7","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"hoverBorderColor":"rgba(97,35,6,1)","borderColor":"rgba(102,37,6,1)","hoverBackgroundColor":"rgba(97,35,6,0.5)","backgroundColor":"rgba(102,37,6,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 8","showLine":true,"data":[{"y":0,"x":0},{"y":8,"x":1},{"y":32,"x":2},{"y":72,"x":3},{"y":128,"x":4},{"y":200,"x":5},{"y":288,"x":6},{"y":392,"x":7},{"y":512,"x":8},{"y":648,"x":9},{"y":800,"x":10},{"y":968,"x":11},{"y":1152,"x":12},{"y":1352,"x":13},{"y":1568,"x":14},{"y":1800,"x":15},{"y":2048,"x":16},{"y":2312,"x":17},{"y":2592,"x":18},{"y":2888,"x":19},{"y":3200,"x":20},{"y":3528,"x":21},{"y":3872,"x":22},{"y":4232,"x":23},{"y":4608,"x":24},{"y":5000,"x":25},{"y":5408,"x":26},{"y":5832,"x":27},{"y":6272,"x":28},{"y":6728,"x":29},{"y":7200,"x":30},{"y":7688,"x":31},{"y":8192,"x":32},{"y":8712,"x":33},{"y":9248,"x":34},{"y":9800,"x":35},{"y":10368,"x":36},{"y":10952,"x":37},{"y":11552,"x":38},{"y":12168,"x":39},{"y":12800,"x":40},{"y":13448,"x":41},{"y":14112,"x":42},{"y":14792,"x":43},{"y":15488,"x":44},{"y":16200,"x":45},{"y":16928,"x":46},{"y":17672,"x":47},{"y":18432,"x":48},{"y":19208,"x":49},{"y":20000,"x":50}],"hoverBorderColor":"rgba(0,0,0,1)","borderColor":"rgba(0,0,0,1)","hoverBackgroundColor":"rgba(0,0,0,0.5)","backgroundColor":"rgba(0,0,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 9","showLine":true,"data":[{"y":0,"x":0},{"y":9,"x":1},{"y":36,"x":2},{"y":81,"x":3},{"y":144,"x":4},{"y":225,"x":5},{"y":324,"x":6},{"y":441,"x":7},{"y":576,"x":8},{"y":729,"x":9},{"y":900,"x":10},{"y":1089,"x":11},{"y":1296,"x":12},{"y":1521,"x":13},{"y":1764,"x":14},{"y":2025,"x":15},{"y":2304,"x":16},{"y":2601,"x":17},{"y":2916,"x":18},{"y":3249,"x":19},{"y":3600,"x":20},{"y":3969,"x":21},{"y":4356,"x":22},{"y":4761,"x":23},{"y":5184,"x":24},{"y":5625,"x":25},{"y":6084,"x":26},{"y":6561,"x":27},{"y":7056,"x":28},{"y":7569,"x":29},{"y":8100,"x":30},{"y":8649,"x":31},{"y":9216,"x":32},{"y":9801,"x":33},{"y":10404,"x":34},{"y":11025,"x":35},{"y":11664,"x":36},{"y":12321,"x":37},{"y":12996,"x":38},{"y":13689,"x":39},{"y":14400,"x":40},{"y":15129,"x":41},{"y":15876,"x":42},{"y":16641,"x":43},{"y":17424,"x":44},{"y":18225,"x":45},{"y":19044,"x":46},{"y":19881,"x":47},{"y":20736,"x":48},{"y":21609,"x":49},{"y":22500,"x":50}],"hoverBorderColor":"rgba(0,0,0,1)","borderColor":"rgba(0,0,0,1)","hoverBackgroundColor":"rgba(0,0,0,0.5)","backgroundColor":"rgba(0,0,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 10","showLine":true,"data":[{"y":0,"x":0},{"y":10,"x":1},{"y":40,"x":2},{"y":90,"x":3},{"y":160,"x":4},{"y":250,"x":5},{"y":360,"x":6},{"y":490,"x":7},{"y":640,"x":8},{"y":810,"x":9},{"y":1000,"x":10},{"y":1210,"x":11},{"y":1440,"x":12},{"y":1690,"x":13},{"y":1960,"x":14},{"y":2250,"x":15},{"y":2560,"x":16},{"y":2890,"x":17},{"y":3240,"x":18},{"y":3610,"x":19},{"y":4000,"x":20},{"y":4410,"x":21},{"y":4840,"x":22},{"y":5290,"x":23},{"y":5760,"x":24},{"y":6250,"x":25},{"y":6760,"x":26},{"y":7290,"x":27},{"y":7840,"x":28},{"y":8410,"x":29},{"y":9000,"x":30},{"y":9610,"x":31},{"y":10240,"x":32},{"y":10890,"x":33},{"y":11560,"x":34},{"y":12250,"x":35},{"y":12960,"x":36},{"y":13690,"x":37},{"y":14440,"x":38},{"y":15210,"x":39},{"y":16000,"x":40},{"y":16810,"x":41},{"y":17640,"x":42},{"y":18490,"x":43},{"y":19360,"x":44},{"y":20250,"x":45},{"y":21160,"x":46},{"y":22090,"x":47},{"y":23040,"x":48},{"y":24010,"x":49},{"y":25000,"x":50}],"hoverBorderColor":"rgba(0,0,0,1)","borderColor":"rgba(0,0,0,1)","hoverBackgroundColor":"rgba(0,0,0,0.5)","backgroundColor":"rgba(0,0,0,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|colorOverflow}}

function p.colorOverflow()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Color overflow' )
        :showLegend( false )

    plot.options.colorPalette = chart.colorPalettes.orange

    for i = 1, 10 do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Custom color palette","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1,"x":1},{"y":4,"x":2},{"y":9,"x":3},{"y":16,"x":4},{"y":25,"x":5},{"y":36,"x":6},{"y":49,"x":7},{"y":64,"x":8},{"y":81,"x":9},{"y":100,"x":10},{"y":121,"x":11},{"y":144,"x":12},{"y":169,"x":13},{"y":196,"x":14},{"y":225,"x":15},{"y":256,"x":16},{"y":289,"x":17},{"y":324,"x":18},{"y":361,"x":19},{"y":400,"x":20},{"y":441,"x":21},{"y":484,"x":22},{"y":529,"x":23},{"y":576,"x":24},{"y":625,"x":25},{"y":676,"x":26},{"y":729,"x":27},{"y":784,"x":28},{"y":841,"x":29},{"y":900,"x":30},{"y":961,"x":31},{"y":1024,"x":32},{"y":1089,"x":33},{"y":1156,"x":34},{"y":1225,"x":35},{"y":1296,"x":36},{"y":1369,"x":37},{"y":1444,"x":38},{"y":1521,"x":39},{"y":1600,"x":40},{"y":1681,"x":41},{"y":1764,"x":42},{"y":1849,"x":43},{"y":1936,"x":44},{"y":2025,"x":45},{"y":2116,"x":46},{"y":2209,"x":47},{"y":2304,"x":48},{"y":2401,"x":49},{"y":2500,"x":50}],"hoverBorderColor":"rgba(0,0,0,1)","borderColor":"rgba(0,0,0,1)","hoverBackgroundColor":"rgba(0,0,0,0.5)","backgroundColor":"rgba(0,0,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":2,"x":1},{"y":8,"x":2},{"y":18,"x":3},{"y":32,"x":4},{"y":50,"x":5},{"y":72,"x":6},{"y":98,"x":7},{"y":128,"x":8},{"y":162,"x":9},{"y":200,"x":10},{"y":242,"x":11},{"y":288,"x":12},{"y":338,"x":13},{"y":392,"x":14},{"y":450,"x":15},{"y":512,"x":16},{"y":578,"x":17},{"y":648,"x":18},{"y":722,"x":19},{"y":800,"x":20},{"y":882,"x":21},{"y":968,"x":22},{"y":1058,"x":23},{"y":1152,"x":24},{"y":1250,"x":25},{"y":1352,"x":26},{"y":1458,"x":27},{"y":1568,"x":28},{"y":1682,"x":29},{"y":1800,"x":30},{"y":1922,"x":31},{"y":2048,"x":32},{"y":2178,"x":33},{"y":2312,"x":34},{"y":2450,"x":35},{"y":2592,"x":36},{"y":2738,"x":37},{"y":2888,"x":38},{"y":3042,"x":39},{"y":3200,"x":40},{"y":3362,"x":41},{"y":3528,"x":42},{"y":3698,"x":43},{"y":3872,"x":44},{"y":4050,"x":45},{"y":4232,"x":46},{"y":4418,"x":47},{"y":4608,"x":48},{"y":4802,"x":49},{"y":5000,"x":50}],"hoverBorderColor":"rgba(120,0,0,1)","borderColor":"rgba(126,0,0,1)","hoverBackgroundColor":"rgba(120,0,0,0.5)","backgroundColor":"rgba(126,0,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":3,"x":1},{"y":12,"x":2},{"y":27,"x":3},{"y":48,"x":4},{"y":75,"x":5},{"y":108,"x":6},{"y":147,"x":7},{"y":192,"x":8},{"y":243,"x":9},{"y":300,"x":10},{"y":363,"x":11},{"y":432,"x":12},{"y":507,"x":13},{"y":588,"x":14},{"y":675,"x":15},{"y":768,"x":16},{"y":867,"x":17},{"y":972,"x":18},{"y":1083,"x":19},{"y":1200,"x":20},{"y":1323,"x":21},{"y":1452,"x":22},{"y":1587,"x":23},{"y":1728,"x":24},{"y":1875,"x":25},{"y":2028,"x":26},{"y":2187,"x":27},{"y":2352,"x":28},{"y":2523,"x":29},{"y":2700,"x":30},{"y":2883,"x":31},{"y":3072,"x":32},{"y":3267,"x":33},{"y":3468,"x":34},{"y":3675,"x":35},{"y":3888,"x":36},{"y":4107,"x":37},{"y":4332,"x":38},{"y":4563,"x":39},{"y":4800,"x":40},{"y":5043,"x":41},{"y":5292,"x":42},{"y":5547,"x":43},{"y":5808,"x":44},{"y":6075,"x":45},{"y":6348,"x":46},{"y":6627,"x":47},{"y":6912,"x":48},{"y":7203,"x":49},{"y":7500,"x":50}],"hoverBorderColor":"rgba(0,120,0,1)","borderColor":"rgba(0,126,0,1)","hoverBackgroundColor":"rgba(0,120,0,0.5)","backgroundColor":"rgba(0,126,0,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":4,"x":1},{"y":16,"x":2},{"y":36,"x":3},{"y":64,"x":4},{"y":100,"x":5},{"y":144,"x":6},{"y":196,"x":7},{"y":256,"x":8},{"y":324,"x":9},{"y":400,"x":10},{"y":484,"x":11},{"y":576,"x":12},{"y":676,"x":13},{"y":784,"x":14},{"y":900,"x":15},{"y":1024,"x":16},{"y":1156,"x":17},{"y":1296,"x":18},{"y":1444,"x":19},{"y":1600,"x":20},{"y":1764,"x":21},{"y":1936,"x":22},{"y":2116,"x":23},{"y":2304,"x":24},{"y":2500,"x":25},{"y":2704,"x":26},{"y":2916,"x":27},{"y":3136,"x":28},{"y":3364,"x":29},{"y":3600,"x":30},{"y":3844,"x":31},{"y":4096,"x":32},{"y":4356,"x":33},{"y":4624,"x":34},{"y":4900,"x":35},{"y":5184,"x":36},{"y":5476,"x":37},{"y":5776,"x":38},{"y":6084,"x":39},{"y":6400,"x":40},{"y":6724,"x":41},{"y":7056,"x":42},{"y":7396,"x":43},{"y":7744,"x":44},{"y":8100,"x":45},{"y":8464,"x":46},{"y":8836,"x":47},{"y":9216,"x":48},{"y":9604,"x":49},{"y":10000,"x":50}],"hoverBorderColor":"rgba(0,0,120,1)","borderColor":"rgba(0,0,126,1)","hoverBackgroundColor":"rgba(0,0,120,0.5)","backgroundColor":"rgba(0,0,126,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set x","color":"rgba(255,0,0,1)","showLine":true,"data":[{"y":0,"x":0},{"y":7,"x":1},{"y":28,"x":2},{"y":63,"x":3},{"y":112,"x":4},{"y":175,"x":5},{"y":252,"x":6},{"y":343,"x":7},{"y":448,"x":8},{"y":567,"x":9},{"y":700,"x":10},{"y":847,"x":11},{"y":1008,"x":12},{"y":1183,"x":13},{"y":1372,"x":14},{"y":1575,"x":15},{"y":1792,"x":16},{"y":2023,"x":17},{"y":2268,"x":18},{"y":2527,"x":19},{"y":2800,"x":20},{"y":3087,"x":21},{"y":3388,"x":22},{"y":3703,"x":23},{"y":4032,"x":24},{"y":4375,"x":25},{"y":4732,"x":26},{"y":5103,"x":27},{"y":5488,"x":28},{"y":5887,"x":29},{"y":6300,"x":30},{"y":6727,"x":31},{"y":7168,"x":32},{"y":7623,"x":33},{"y":8092,"x":34},{"y":8575,"x":35},{"y":9072,"x":36},{"y":9583,"x":37},{"y":10108,"x":38},{"y":10647,"x":39},{"y":11200,"x":40},{"y":11767,"x":41},{"y":12348,"x":42},{"y":12943,"x":43},{"y":13552,"x":44},{"y":14175,"x":45},{"y":14812,"x":46},{"y":15463,"x":47},{"y":16128,"x":48},{"y":16807,"x":49},{"y":17500,"x":50}],"fill":false,"hoverBackgroundColor":"rgba(242,0,0,0.5)","backgroundColor":"rgba(255,0,0,0.3)","borderColor":"rgba(255,0,0,1)","hoverBorderColor":"rgba(242,0,0,1)","clip":5,"baseColor":"rgba(255,0,0,1)"}]}}
Code

{{Chart data|Chart data/doc examples|customColorPalette}}

function p.customColorPalette()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Custom color palette' )
    plot.options.colorPalette = { -- You can define a custom color palette
        chart.rgba.new( 0, 0, 0 ),
        chart.rgba.new( 126, 0, 0 ),
        chart.rgba.new( 0, 126, 0 ),
        chart.rgba.new( 0, 0, 126 ),
    }

    for i = 1, #plot.options.colorPalette do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return i*x^2 end, 0, 50 )
        set.label = 'Set ' .. i
    end
    
    -- Or set the color on a per set basis
    plot:newDataSet{
    	data = chart.generateXYFromFunc( function(x) return 7*x^2 end, 0, 50 ),
    	label = 'Set x',
    	color = chart.rgba.new( 255, 0, 0 )
    }

    return plot
end
{"type":"bar","options":{"tooltips":{"intersect":false},"aspectRatio":1,"scales":{"y":{"ticks":{"beginAtZero":true}},"x":{"ticks":{"beginAtZero":true}}},"title":{"display":true,"font":{"size":18},"text":"Color options","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"label":"Set 1","borderWidth":1,"hoverBackgroundColor":"rgba(31,128,32,0.4)","backgroundColor":"rgba(120,198,121,0.8)","hoverBorderColor":"rgba(31,128,32,1)","borderColor":"rgba(120,198,121,1)","data":[1,1.4142135623730951,1.7320508075688772,2,2.23606797749979,2.449489742783178],"color":"rgba(120,198,121,1)","clip":5,"baseColor":"rgba(120,198,121,1)"},{"label":"Set 2","borderWidth":1,"hoverBackgroundColor":"rgba(148,78,0,0.4)","backgroundColor":"rgba(254,153,41,0.8)","hoverBorderColor":"rgba(148,78,0,1)","borderColor":"rgba(254,153,41,1)","data":[1.4142135623730951,2,2.449489742783178,2.8284271247461903,3.1622776601683795,3.4641016151377544],"color":"rgba(254,153,41,1)","clip":5,"baseColor":"rgba(254,153,41,1)"}]}}
Code

{{Chart data|Chart data/doc examples|colorOptions}}

function p.colorOptions()
    local plot = chart.newChart{ type = 'bar' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Color options' )
    plot:setOptions{
        backgroundAlpha = 0.8,
        hoverLightenValue = 0.5,
        hoverAlpha = 0.4,
        hoverSaturateValue = 1.5,
    }

    for i = 1, 2 do
        local set = plot:newDataSet()
        for j = 1, 6 do
            set:addDataPoint( math.sqrt( i*j ) )
        end
        set.label = 'Set ' .. i

        if i == 1 then
            set.color = chart.colorPalettes.green[3]
        else
            set.color = chart.colorPalettes.orange[3]
        end
    end

    local labels = {}

    for i = 1, 6 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end

Examples

Prefix text message
{"type":"line","options":{"tooltips":{"intersect":false},"scales":{"y":{"scaleLabel":{"display":true,"labelString":"y axis label"}},"x":{"scaleLabel":{"display":true,"labelString":"x axis label"}}},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Line chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5"],"datasets":[{"label":"Set 1","data":[1,4,9,10,25],"hoverBorderColor":"rgba(151,198,222,1)","borderDash":[5,5],"borderColor":"rgba(166,206,227,1)","hoverBackgroundColor":"rgba(151,198,222,0.5)","backgroundColor":"rgba(166,206,227,0.3)","clip":5,"fill":true},{"label":"Set 2","data":[4,9,16,11,36],"hoverBorderColor":"rgba(29,114,171,1)","borderDash":[5,5],"borderColor":"rgba(31,120,180,1)","hoverBackgroundColor":"rgba(29,114,171,0.5)","backgroundColor":"rgba(31,120,180,0.3)","clip":5,"fill":true}]}}
Affix text message
Code

{{#Invoke:Chart data/doc examples|line}}

function p.line()
    local plot = chart.newChart{ type = 'line' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Line chart' )
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )
    plot.options.fill = true

    for i = 1, 2 do
        local set = plot:newDataSet()
        set.data = { i^2, (i+1)^2, (i+2)^2, (i+3^2), (i+4)^2 }
        set.label = 'Set ' .. i
        set.borderDash = {5, 5}
    end

    local labels = {}

    for i = 1, 5 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return 'Prefix text message' .. plot .. 'Affix text message'
end
{"type":"bar","options":{"tooltips":{"intersect":false},"aspectRatio":1,"scales":{"y":{"scaleLabel":{"display":true,"labelString":"y axis label"},"ticks":{"beginAtZero":true}},"x":{"scaleLabel":{"display":true,"labelString":"x axis label"},"ticks":{"beginAtZero":true}}},"title":{"display":true,"font":{"size":18},"text":"Bar chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"label":"Set 1","borderWidth":1,"hoverBackgroundColor":"rgba(109,193,110,0.5)","backgroundColor":"rgba(120,198,121,0.4)","hoverBorderColor":"rgba(109,193,110,1)","borderColor":"rgba(120,198,121,1)","data":[1,1.4142135623730951,1.7320508075688772,2,2.23606797749979,2.449489742783178],"color":"rgba(120,198,121,1)","clip":5,"baseColor":"rgba(120,198,121,1)"},{"label":"Set 2","borderWidth":1,"hoverBackgroundColor":"rgba(254,146,26,0.5)","backgroundColor":"rgba(254,153,41,0.4)","hoverBorderColor":"rgba(254,146,26,1)","borderColor":"rgba(254,153,41,1)","data":[1.4142135623730951,2,2.449489742783178,2.8284271247461903,3.1622776601683795,3.4641016151377544],"color":"rgba(254,153,41,1)","clip":5,"baseColor":"rgba(254,153,41,1)"}]}}
Code

{{Chart data|Chart data/doc examples|bar}}

function p.bar()
    local plot = chart.newChart{ type = 'bar' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Bar chart' )
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )

    for i = 1, 2 do
        local set = plot:newDataSet()
        for j = 1, 6 do
            set:addDataPoint( math.sqrt( i*j ) )
        end
        set.label = 'Set ' .. i

        if i == 1 then
            set.color = chart.colorPalettes.green[3]
        else
            set.color = chart.colorPalettes.orange[3]
        end
    end

    local labels = {}

    for i = 1, 6 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"bar","options":{"tooltips":{"intersect":false},"aspectRatio":1,"scales":{"y":{"ticks":{"beginAtZero":true,"format":[]},"type":"category","scaleLabel":{"display":true,"labelString":"y axis label"}},"x":{"offset":false,"type":"linear","scaleLabel":{"display":true,"labelString":"x axis label"},"gridLines":{"offsetGridLines":false},"ticks":{"beginAtZero":true,"format":[]}}},"title":{"display":true,"font":{"size":18},"text":"HorizontalBar chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"isFinished":true,"height":"min(10vh, 100vh - 2em)","minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"label":"Set 1","indexAxis":"y","data":[1,1.4142135623730951,1.7320508075688772,2,2.23606797749979,2.449489742783178],"hoverBackgroundColor":"rgba(109,193,110,0.5)","backgroundColor":"rgba(120,198,121,0.4)","hoverBorderColor":"rgba(109,193,110,1)","borderWidth":1,"borderColor":"rgba(120,198,121,1)","color":"rgba(120,198,121,1)","clip":5,"baseColor":"rgba(120,198,121,1)"},{"label":"Set 2","indexAxis":"y","data":[1.4142135623730951,2,2.449489742783178,2.8284271247461903,3.1622776601683795,3.4641016151377544],"hoverBackgroundColor":"rgba(254,146,26,0.5)","backgroundColor":"rgba(254,153,41,0.4)","hoverBorderColor":"rgba(254,146,26,1)","borderWidth":1,"borderColor":"rgba(254,153,41,1)","color":"rgba(254,153,41,1)","clip":5,"baseColor":"rgba(254,153,41,1)"}]}}
Code

{{Chart data|Chart data/doc examples|horizontalBar}}

function p.horizontalBar()
    local plot = chart.newChart{ type = 'bar' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'HorizontalBar chart' )
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )
        :flipXY() -- This is the important line

    for i = 1, 2 do
        local set = plot:newDataSet()
        for j = 1, 6 do
            set:addDataPoint( math.sqrt( i*j ) )
        end
        set.label = 'Set ' .. i

        if i == 1 then
            set.color = chart.colorPalettes.green[3]
        else
            set.color = chart.colorPalettes.orange[3]
        end
    end

    local labels = {}

    for i = 1, 6 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"radar","options":{"scale":{"min":0,"ticks":{"showLabelBackdrop":false,"z":1},"max":5},"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Radar chart","position":"top"},"fill":false,"maintainAspectRatio":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vw, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"label":"Set 1","data":[1.1054339995714253,1.7620466300282018,1.9252051673625146,2.8252091418960124,2.67948377636813,3.0654489855507467],"hoverBorderColor":"rgba(151,198,222,1)","borderColor":"rgba(166,206,227,1)","hoverBackgroundColor":"rgba(151,198,222,0.5)","backgroundColor":"rgba(166,206,227,0.3)","clip":5,"fill":false},{"label":"Set 2","data":[1.5964949166349123,2.392213408807727,3.0500465353746513,3.368869516504649,4.3642936109400186,4.637400496548407],"hoverBorderColor":"rgba(29,114,171,1)","borderColor":"rgba(31,120,180,1)","hoverBackgroundColor":"rgba(29,114,171,0.5)","backgroundColor":"rgba(31,120,180,0.3)","clip":5,"fill":false},{"label":"Set 3","data":[1.919159774308544,2.717299940079637,3.872820717553868,4.002878885815963,4.714183860661343,5.107611022043776],"hoverBackgroundColor":"rgba(169,219,124,0.5)","borderColor":"rgba(178,223,138,1)","backgroundColor":"rgba(178,223,138,0.3)","hoverBorderColor":"rgba(169,219,124,1)","clip":5,"fill":true},{"label":"Set 4","data":[2.7481761049604683,3.2205473092944183,3.583229637507928,5.515767517019176,6.21912330282,5.9950528373603325],"hoverBorderColor":"rgba(48,152,42,1)","borderColor":"rgba(51,160,44,1)","hoverBackgroundColor":"rgba(48,152,42,0.5)","backgroundColor":"rgba(51,160,44,0.3)","clip":5,"fill":false},{"label":"Set 5","data":[2.9424090583403157,3.961925189685549,4.827462715401098,6.1926825505408845,6.644525966739941,6.899639803830769],"hoverBorderColor":"rgba(250,135,134,1)","borderColor":"rgba(251,154,153,1)","hoverBackgroundColor":"rgba(250,135,134,0.5)","backgroundColor":"rgba(251,154,153,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|radar}}

function p.radar()
    local plot = chart.newChart{ type = 'radar' }
        :setDimensions( '10vw', nil, 300, nil, true ) -- Radar chart is always square. height = width
        :setTitle( 'Radar chart' )
        :setRadialLimits( 0, 5 )

    for i = 1, 5 do
        local set = plot:newDataSet()
        for j = 1, 6 do
            set:addDataPoint( math.sqrt( i*j*(math.random()+1) ) )
        end
        set.label = 'Set ' .. i

        if i == 3 then
            set.fill = true
        end
    end

    local labels = {}

    for i = 1, 6 do
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"pie","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Pie chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vw, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"hoverBackgroundColor":["rgba(151,198,222,0.9)","rgba(29,114,171,0.9)","rgba(169,219,124,0.9)","rgba(48,152,42,0.9)","rgba(250,135,134,0.9)","rgba(216,25,27,0.9)"],"backgroundColor":["rgba(166,206,227,0.8)","rgba(31,120,180,0.8)","rgba(178,223,138,0.8)","rgba(51,160,44,0.8)","rgba(251,154,153,0.8)","rgba(227,26,28,0.8)"],"borderColor":["rgba(166,206,227,1)","rgba(31,120,180,1)","rgba(178,223,138,1)","rgba(51,160,44,1)","rgba(251,154,153,1)","rgba(227,26,28,1)"],"hoverBorderColor":["rgba(151,198,222,1)","rgba(29,114,171,1)","rgba(169,219,124,1)","rgba(48,152,42,1)","rgba(250,135,134,1)","rgba(216,25,27,1)"],"data":[1,1.4,1.7,2,2.2,2.4],"clip":5}]}}
Code

{{Chart data|Chart data/doc examples|pie}}

function p.pie()
    local plot = chart.newChart{ type = 'pie' }
        :setDimensions( '10vw', nil, 300, nil, true ) -- Pie chart is always square. height = width
        :setTitle( 'Pie chart' )

    local labels = {}
    local set = plot:newDataSet()

    for i = 1, 6 do
        set:addDataPoint( math.floor( math.sqrt( i ) * 10 + 0.5 ) / 10 )
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"doughnut","options":{"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Doughnut chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vw, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"hoverBackgroundColor":["rgba(151,198,222,0.9)","rgba(29,114,171,0.9)","rgba(169,219,124,0.9)","rgba(48,152,42,0.9)","rgba(250,135,134,0.9)","rgba(216,25,27,0.9)"],"backgroundColor":["rgba(166,206,227,0.8)","rgba(31,120,180,0.8)","rgba(178,223,138,0.8)","rgba(51,160,44,0.8)","rgba(251,154,153,0.8)","rgba(227,26,28,0.8)"],"borderColor":["rgba(166,206,227,1)","rgba(31,120,180,1)","rgba(178,223,138,1)","rgba(51,160,44,1)","rgba(251,154,153,1)","rgba(227,26,28,1)"],"hoverBorderColor":["rgba(151,198,222,1)","rgba(29,114,171,1)","rgba(169,219,124,1)","rgba(48,152,42,1)","rgba(250,135,134,1)","rgba(216,25,27,1)"],"data":[1,1.4,1.7,2,2.2,2.4],"clip":5}]}}
Code

{{Chart data|Chart data/doc examples|doughnut}}

function p.doughnut()
    local plot = chart.newChart{ type = 'doughnut' }
        :setDimensions( '10vw', nil, 300, nil, true ) -- doughnut chart is always square. height = width
        :setTitle( 'Doughnut chart' )

    local labels = {}
    local set = plot:newDataSet()

    for i = 1, 6 do
        set:addDataPoint( math.floor( math.sqrt( i ) * 10 + 0.5 ) / 10 )
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"polarArea","options":{"scale":{"ticks":{"showLabelBackdrop":false,"z":1}},"tooltips":{"intersect":false},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"PolarArea chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vw, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"labels":["Value 1","Value 2","Value 3","Value 4","Value 5","Value 6"],"datasets":[{"hoverBackgroundColor":["rgba(151,198,222,0.6)","rgba(29,114,171,0.6)","rgba(169,219,124,0.6)","rgba(48,152,42,0.6)","rgba(250,135,134,0.6)","rgba(216,25,27,0.6)"],"backgroundColor":["rgba(166,206,227,0.5)","rgba(31,120,180,0.5)","rgba(178,223,138,0.5)","rgba(51,160,44,0.5)","rgba(251,154,153,0.5)","rgba(227,26,28,0.5)"],"borderColor":["rgba(166,206,227,1)","rgba(31,120,180,1)","rgba(178,223,138,1)","rgba(51,160,44,1)","rgba(251,154,153,1)","rgba(227,26,28,1)"],"hoverBorderColor":["rgba(151,198,222,1)","rgba(29,114,171,1)","rgba(169,219,124,1)","rgba(48,152,42,1)","rgba(250,135,134,1)","rgba(216,25,27,1)"],"data":[1,1.4,1.7,2,2.2,2.4],"clip":5}]}}
Code

{{Chart data|Chart data/doc examples|polarArea}}

function p.polarArea()
    local plot = chart.newChart{ type = 'polarArea' }
        :setDimensions( '10vw', nil, 300, nil, true ) -- polarArea chart is always square. height = width
        :setTitle( 'PolarArea chart' )

    local labels = {}
    local set = plot:newDataSet()

    for i = 1, 6 do
        set:addDataPoint( math.floor( math.sqrt( i ) * 10 + 0.5 ) / 10 )
        table.insert( labels, 'Value ' .. i )
    end

    plot:addDataLabels( labels )

    return plot
end
{"type":"bubble","options":{"tooltips":{"intersect":false},"scales":{"y":{"scaleLabel":{"display":true,"labelString":"y axis label"}},"x":{"scaleLabel":{"display":true,"labelString":"x axis label"}}},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Bubble chart","position":"top"},"maintainAspectRatio":false,"fill":true},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"label":"Set 1","data":[{"y":11.048083263937423,"x":2.219843274084778,"r":8.532074682196637},{"y":8.71853323128006,"x":9.954516738632003,"r":13.49244370753525},{"y":8.613424966397428,"x":2.7439800942055785,"r":13.25695966987729},{"y":18.094117444983738,"x":4.186602274042835,"r":16.881854206734268},{"y":4.612396547855994,"x":2.277247464413404,"r":14.997900517190761}],"hoverBorderColor":"rgba(151,198,222,1)","borderColor":"rgba(166,206,227,1)","hoverBackgroundColor":"rgba(151,198,222,0.5)","backgroundColor":"rgba(166,206,227,0.4)","clip":5,"fill":true},{"label":"Set 2","data":[{"y":9.631372629493182,"x":3.352532812092701,"r":11.739741960419222},{"y":5.929812428508798,"x":8.881179759689225,"r":6.049418293893998},{"y":18.677494655678746,"x":9.014807063627433,"r":12.46291157671386},{"y":11.393702417329747,"x":7.315542133206288,"r":13.304396268587743},{"y":15.319780258145082,"x":9.174658585886778,"r":13.802514711302946}],"hoverBorderColor":"rgba(29,114,171,1)","borderColor":"rgba(31,120,180,1)","hoverBackgroundColor":"rgba(29,114,171,0.5)","backgroundColor":"rgba(31,120,180,0.4)","clip":5,"fill":true},{"label":"Set 3","data":[{"y":14.656562337026262,"x":8.20528511805706,"r":11.876036434842291},{"y":3.3071613885961293,"x":9.497465882216332,"r":9.918058589062682},{"y":8.98751901881188,"x":8.447294327638716,"r":5.013033160945882},{"y":6.531544386656742,"x":7.747231953659669,"r":9.845782897828977},{"y":5.559363572653087,"x":4.449881270737332,"r":14.33752677838203}],"hoverBorderColor":"rgba(169,219,124,1)","borderColor":"rgba(178,223,138,1)","hoverBackgroundColor":"rgba(169,219,124,0.5)","backgroundColor":"rgba(178,223,138,0.4)","clip":5,"fill":true},{"label":"Set 4","data":[{"y":12.730377331716184,"x":1.1994582233947972,"r":6.372245744044076},{"y":5.878369820247577,"x":5.693431424765583,"r":7.076752543019481},{"y":5.287218217406058,"x":4.050987662771245,"r":5.100100396713288},{"y":13.904402020342834,"x":9.440298522561928,"r":5.766213504023018},{"y":11.438156744203603,"x":6.534048037852182,"r":5.737508873332994}],"hoverBorderColor":"rgba(48,152,42,1)","borderColor":"rgba(51,160,44,1)","hoverBackgroundColor":"rgba(48,152,42,0.5)","backgroundColor":"rgba(51,160,44,0.4)","clip":5,"fill":true},{"label":"Set 5","data":[{"y":12.199589606467443,"x":8.488617394347031,"r":16.321413645670475},{"y":6.562817556114316,"x":9.54453962833832,"r":15.370786879384324},{"y":1.2357927212658304,"x":2.213936220954143,"r":11.41158394115585},{"y":1.5438295442349415,"x":8.361116246488464,"r":11.143994036197661},{"y":10.123662105819054,"x":7.140883541265914,"r":9.060997974155935}],"hoverBorderColor":"rgba(250,135,134,1)","borderColor":"rgba(251,154,153,1)","hoverBackgroundColor":"rgba(250,135,134,0.5)","backgroundColor":"rgba(251,154,153,0.4)","clip":5,"fill":true}]}}
Code

{{Chart data|Chart data/doc examples|bubble}}

function p.bubble()
    local plot = chart.newChart{ type = 'bubble' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Bubble chart' )
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )

    for i = 1, 5 do
        local set = plot:newDataSet()
        for j = 1, 5 do
            set:addDataPoint{ x = math.random() * 10, y = math.random() * 20, r = math.random() * 15 + 5 }
        end
        set.label = 'Set ' .. i
    end

    return plot
end
{"type":"scatter","options":{"tooltips":{"intersect":false},"scales":{"y":{"ticks":{"format":{"maximumSignificantDigits":3}},"type":"logarithmic","scaleLabel":{"display":true,"labelString":"y axis label"}},"x":{"scaleLabel":{"display":true,"labelString":"x axis label"}}},"aspectRatio":1,"title":{"display":true,"font":{"size":18},"text":"Scatter chart","position":"top"},"maintainAspectRatio":false,"fill":false},"minWidth":"300px","resizable":true,"width":"min(10vw, 100%, 100vw - 2em)","isChartObj":true,"height":"min(10vh, 100vh - 2em)","isFinished":true,"minHeight":"300px","data":{"datasets":[{"pointRadius":0,"label":"Set 1","showLine":true,"data":[{"y":0,"x":0},{"y":1.9933466539753062,"x":1},{"y":3.9470917115432527,"x":2},{"y":5.823212366975177,"x":3},{"y":7.586780454497614,"x":4},{"y":9.207354924039482,"x":5},{"y":10.660195429836131,"x":6},{"y":11.9272486499423,"x":7},{"y":12.997868015207526,"x":8},{"y":13.869238154390976,"x":9},{"y":14.546487134128409,"x":10},{"y":15.04248201909795,"x":11},{"y":15.377315902755754,"x":12},{"y":15.57750685910732,"x":13},{"y":15.674940750779525,"x":14},{"y":15.705600040299336,"x":15},{"y":15.7081292828621,"x":16},{"y":15.722294489865844,"x":17},{"y":15.787397783525737,"x":18},{"y":15.940710545286406,"x":19},{"y":16.21598752346036,"x":20},{"y":16.642121137932058,"x":21},{"y":17.24198963055242,"x":22},{"y":18.031544981832678,"x":23},{"y":19.019176955820797,"x":24},{"y":20.205378626684308,"x":25},{"y":21.582726721399233,"x":26},{"y":23.136177562220062,"x":27},{"y":24.843666810638393,"x":28},{"y":26.676989102931213,"x":29},{"y":28.60292250900537,"x":30},{"y":30.584552985912516,"x":31},{"y":32.582746024252465,"x":32},{"y":34.55770681756689,"x":33},{"y":36.47056675569304,"x":34},{"y":38.28493299359395,"x":35},{"y":39.968339319245764,"x":36},{"y":41.49354047905813,"x":37},{"y":42.83959836015743,"x":38},{"y":43.99271672687303,"x":39},{"y":44.94679123311691,"x":40},{"y":45.703652783398866,"x":41},{"y":46.2729945404414,"x":42},{"y":46.67198548937057,"x":43},{"y":46.92458596445881,"x":44},{"y":47.060592426208785,"x":45},{"y":47.114449570501236,"x":46},{"y":47.12387712726679,"x":47},{"y":47.1283660938851,"x":48},{"y":47.16760435374036,"x":49},{"y":47.279894445553154,"x":50},{"y":47.50062656203229,"x":51},{"y":47.860867654571734,"x":52},{"y":48.38612289193597,"x":53},{"y":49.09531884966754,"x":54},{"y":50.000048967246485,"x":55},{"y":51.104111354243415,"x":56},{"y":52.40335737167662,"x":57},{"y":53.885857025156454,"x":58},{"y":55.532374576114385,"x":59},{"y":57.317135409997825,"x":60},{"y":59.208853588815856,"x":61},{"y":61.17197912275845,"x":62},{"y":63.168115236105685,"x":63},{"y":65.1575491255077,"x":64},{"y":67.1008351841332,"x":65},{"y":68.96036757353612,"x":66},{"y":70.70187944976225,"x":67},{"y":72.29580907428247,"x":68},{"y":73.71847834722053,"x":69},{"y":74.95303677847436,"x":70},{"y":75.99013326358181,"x":71},{"y":76.82828888274639,"x":72},{"y":77.47395586070252,"x":73},{"y":77.94126033687658,"x":74},{"y":78.25143920078558,"x":75},{"y":78.431993444269,"x":76},{"y":78.51559178372851,"x":77},{"y":78.53876826149722,"x":78},{"y":78.54046574886159,"x":79},{"y":78.56048341667467,"x":80},{"y":78.63789006800766,"x":81},{"y":78.80946658826026,"x":82},{"y":79.10823960732851,"x":83},{"y":79.56216483209248,"x":84},{"y":80.19301254060221,"x":85},{"y":81.01549966979202,"x":86},{"y":82.03670309764684,"x":87},{"y":83.25577751040937,"x":88},{"y":84.66398910257209,"x":89},{"y":86.24506376614161,"x":90},{"y":87.97583588796859,"x":91},{"y":89.82717188964051,"x":92},{"y":91.7651316913169,"x":93},{"y":93.75232179560817,"x":94},{"y":95.74938604831476,"x":95},{"y":97.71657464409948,"x":96},{"y":99.61532882578848,"x":97},{"y":101.40981810034067,"x":98},{"y":103.06836868753552,"x":99},{"y":104.56472625363814,"x":100}],"hoverBorderColor":"rgba(151,198,222,1)","borderColor":"rgba(166,206,227,1)","hoverBackgroundColor":"rgba(151,198,222,0.5)","backgroundColor":"rgba(166,206,227,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 2","showLine":true,"data":[{"y":0,"x":0},{"y":3.973430882914549,"x":1},{"y":15.579532979333443,"x":2},{"y":33.90980227089265,"x":3},{"y":57.55923766474702,"x":4},{"y":84.77538469723409,"x":5},{"y":113.63976660229913,"x":6},{"y":142.2592603575504,"x":7},{"y":168.94457294075485,"x":8},{"y":192.3557669832144,"x":9},{"y":211.60028794336333,"x":10},{"y":226.27626529488512,"x":11},{"y":236.461844373145,"x":12},{"y":242.6587199455356,"x":13},{"y":245.70376754044858,"x":14},{"y":246.6658726258505,"x":15},{"y":246.74532556710977,"x":16},{"y":247.19054402606588,"x":17},{"y":249.24192877527335,"x":18},{"y":254.10625268860522,"x":19},{"y":262.95825136102206,"x":20},{"y":276.960195969605,"x":21},{"y":297.28620642007724,"x":22},{"y":325.1366144318552,"x":23},{"y":361.7290920768248,"x":24},{"y":408.25732544767106,"x":25},{"y":465.81409273060046,"x":26},{"y":535.2827121905751,"x":27},{"y":617.2077805980156,"x":28},{"y":711.6617475979107,"x":29},{"y":818.127176056166,"x":30},{"y":935.4148813480903,"x":31},{"y":1061.63533848094,"x":32},{"y":1194.235100488909,"x":33},{"y":1330.1022394814624,"x":34},{"y":1465.7360943239785,"x":35},{"y":1597.4681479383669,"x":36},{"y":1721.713901487236,"x":37},{"y":1835.2311876596034,"x":38},{"y":1935.3591250108939,"x":39},{"y":2020.2140421533952,"x":40},{"y":2088.823877745483,"x":41},{"y":2141.19002373972,"x":42},{"y":2178.274229520017,"x":43},{"y":2201.9167679358843,"x":44},{"y":2214.6993595057397,"x":45},{"y":2219.7713583313043,"x":46},{"y":2220.6597955057377,"x":47},{"y":2221.0828906792585,"x":48},{"y":2224.7829004709865,"x":49},{"y":2235.388418782648,"x":50},{"y":2256.3095237856473,"x":51},{"y":2290.662652648431,"x":52},{"y":2341.21688851353,"x":53},{"y":2410.350332950521,"x":54},{"y":2500.0048967270463,"x":55},{"y":2611.6301973069108,"x":56},{"y":2746.1118638236544,"x":57},{"y":2903.685587335603,"x":58},{"y":3083.8446260618753,"x":59},{"y":3285.2540116080263,"x":60},{"y":3505.6883433018324,"x":61},{"y":3742.0110297951956,"x":62},{"y":3990.2107824819273,"x":63},{"y":4245.506208042949,"x":64},{"y":4502.522082408208,"x":65},{"y":4755.532295877211,"x":66},{"y":4998.7557577287125,"x":67},{"y":5226.6840097051045,"x":68},{"y":5434.414049829621,"x":69},{"y":5617.957722315329,"x":70},{"y":5774.500353416923,"x":71},{"y":5902.585972650733,"x":72},{"y":6002.213836706082,"x":73},{"y":6074.84006290077,"x":74},{"y":6123.287736994243,"x":75},{"y":6151.577595641855,"x":76},{"y":6164.698153149096,"x":77},{"y":6168.338120033164,"x":78},{"y":6168.604760048101,"x":79},{"y":6171.7495546616165,"x":80},{"y":6183.917754348058,"x":81},{"y":6210.932023926111,"x":82},{"y":6258.1135737705,"x":83},{"y":6330.138072769053,"x":84},{"y":6430.919260337184,"x":85},{"y":6563.511186746071,"x":86},{"y":6730.020655131458,"x":87},{"y":6931.524488862788,"x":88},{"y":7167.991050760445,"x":89},{"y":7438.211024025833,"x":90},{"y":7739.747700186781,"x":91},{"y":8068.920809691022,"x":92},{"y":8420.839394324732,"x":93},{"y":8789.497842067267,"x":94},{"y":9167.944928629213,"x":95},{"y":9548.528960175865,"x":96},{"y":9923.213737069966,"x":97},{"y":10283.951207144182,"x":98},{"y":10623.088623909753,"x":99},{"y":10933.781976498281,"x":100}],"hoverBackgroundColor":"rgba(29,114,171,0.5)","borderColor":"rgba(31,120,180,1)","backgroundColor":"rgba(31,120,180,0.3)","hoverBorderColor":"rgba(29,114,171,1)","clip":5,"fill":"+2"},{"pointRadius":0,"label":"Set 3","showLine":true,"data":[{"y":0,"x":0},{"y":7.9204251552598635,"x":1},{"y":61.49384549244179,"x":2},{"y":197.463979945545,"x":3},{"y":436.6892992906856,"x":4},{"y":780.5570557294196,"x":5},{"y":1211.4221205814738,"x":6},{"y":1696.7615710413831,"x":7},{"y":2195.9192609695324,"x":8},{"y":2667.827942660737,"x":9},{"y":3078.0408661460015,"x":10},{"y":3403.756652046947,"x":11},{"y":3636.148479874119,"x":12},{"y":3780.017874373783,"x":13},{"y":3851.391998439837,"x":14},{"y":3874.0355390530285,"x":15},{"y":3875.9074739500593,"x":16},{"y":3886.4025282879556,"x":17},{"y":3934.88147390843,"x":18},{"y":4050.634221856461,"x":19},{"y":4264.1277232612865,"x":20},{"y":4609.205131711569,"x":21},{"y":5125.805688401238,"x":22},{"y":5862.715488368785,"x":23},{"y":6879.7896122775255,"x":24},{"y":8248.993837787672,"x":25},{"y":10053.53826638107,"x":26},{"y":12384.395875227883,"x":27},{"y":15333.704454110702,"x":28},{"y":18984.992685642446,"x":29},{"y":23400.828219245912,"x":30},{"y":28609.246002401735,"x":31},{"y":34590.994604095766,"x":32},{"y":41270.026473943246,"x":33},{"y":48509.582516905495,"x":34},{"y":56115.608157485614,"x":35},{"y":63848.148988487745,"x":36},{"y":71440.00546471773,"x":37},{"y":78620.56697737212,"x":38},{"y":85141.7057513731,"x":39},{"y":90802.13879887991,"x":40},{"y":95466.88123415234,"x":41},{"y":99079.27427855565,"x":42},{"y":101664.38323202809,"x":43},{"y":103324.0326635907,"x":44},{"y":104225.06390428526,"x":45},{"y":104583.30572014325,"x":46},{"y":104646.09934487379,"x":47},{"y":104676.00759679667,"x":48},{"y":104937.6796223824,"x":49},{"y":105688.92848485557,"x":50},{"y":107176.11609769895,"x":51},{"y":109633.10205967678,"x":52},{"y":113282.40808429162,"x":53},{"y":118336.91813560815,"x":54},{"y":125000.36725470831,"x":55},{"y":133465.04041927707,"x":56},{"y":143905.48138255192,"x":57},{"y":156467.58640517376,"x":58},{"y":171253.21490900547,"x":59},{"y":188301.3490395758,"x":60},{"y":207567.7878465766,"x":61},{"y":228906.22059176356,"x":62},{"y":252054.0945241698,"x":63},{"y":276626.7793132064,"x":64},{"y":302122.9921645934,"x":65},{"y":327943.2551315146,"x":66},{"y":353421.4269817404,"x":67},{"y":377867.34925724537,"x":68},{"y":400616.73446219595,"x":69},{"y":421082.9917806149,"x":70},{"y":438805.0513867522,"x":71},{"y":453485.5802620571,"x":72},{"y":465015.2498514649,"x":73},{"y":473480.69084743666,"x":74},{"y":479156.0780603209,"x":75},{"y":482480.493653294,"x":76},{"y":484024.9236625595,"x":77},{"y":484453.67816784413,"x":78},{"y":484485.09087482246,"x":79},{"y":484855.62854086317,"x":80},{"y":486290.24455602345,"x":81},{"y":489480.23982156056,"x":82},{"y":495068.34808371164,"x":83},{"y":503639.4887555556,"x":84},{"y":515714.78889182006,"x":85},{"y":531746.1383825026,"x":86},{"y":552108.7063260501,"x":87},{"y":577089.4606527142,"x":88},{"y":606870.7162089166,"x":89},{"y":641508.9840731254,"x":90},{"y":680910.7734859146,"x":91},{"y":724808.3365360127,"x":92},{"y":772739.4359716383,"x":93},{"y":824035.8301112939,"x":94},{"y":877825.0982410081,"x":95},{"y":933049.5428783706,"x":96},{"y":988504.199426806,"x":97},{"y":1042893.6212692704,"x":98},{"y":1094904.414889495,"x":99},{"y":1143287.9192895053,"x":100}],"hoverBorderColor":"rgba(169,219,124,1)","borderColor":"rgba(178,223,138,1)","hoverBackgroundColor":"rgba(169,219,124,0.5)","backgroundColor":"rgba(178,223,138,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 4","showLine":true,"data":[{"y":0,"x":0},{"y":15.788152981299094,"x":1},{"y":242.72184785413842,"x":2},{"y":1149.874690051036,"x":3},{"y":3313.065840546832,"x":4},{"y":7186.865850564032,"x":5},{"y":12913.996553425022,"x":6},{"y":20237.697157477312,"x":7},{"y":28542.268726134032,"x":8},{"y":37000.74109170068,"x":9},{"y":44774.68185771427,"x":10},{"y":51200.94823580123,"x":11},{"y":55914.20384434945,"x":12},{"y":58883.25436560588,"x":13},{"y":60370.34138357079,"x":14},{"y":60844.0527182723,"x":15},{"y":60883.255689219,"x":16},{"y":61103.165055902406,"x":17},{"y":62121.53905961844,"x":18},{"y":64569.987655445286,"x":19},{"y":69147.04195884646,"x":20},{"y":76706.95015152202,"x":21},{"y":88379.08852764076,"x":22},{"y":105713.81804420888,"x":23},{"y":130847.936054724,"x":24},{"y":166674.04378168558,"x":25},{"y":216982.76898643246,"x":26},{"y":286527.581970098,"x":27},{"y":380945.44443072815,"x":28},{"y":506462.4429941123,"x":29},{"y":669332.076201637,"x":30},{"y":875001.0002474617,"x":31},{"y":1127069.5919115397,"x":32},{"y":1426197.4752397547,"x":33},{"y":1769171.967473602,"x":34},{"y":2148382.2982041105,"x":35},{"y":2551904.4836776364,"x":36},{"y":2964298.758574399,"x":37},{"y":3368073.512158478,"x":38},{"y":3745614.9427629327,"x":39},{"y":4081264.77611376,"x":40},{"y":4363185.192239676,"x":41},{"y":4584694.717762502,"x":42},{"y":4744878.618991024,"x":43},{"y":4848437.452917212,"x":44},{"y":4904893.252995133,"x":45},{"y":4927384.883268003,"x":46},{"y":4931329.927375586,"x":47},{"y":4933209.207268131,"x":48},{"y":4949658.954228095,"x":49},{"y":4996961.382827587,"x":50},{"y":5090932.667125815,"x":51},{"y":5247135.388238346,"x":52},{"y":5481296.519060975,"x":53},{"y":5809788.727554688,"x":54},{"y":6250024.48365921,"x":55},{"y":6820612.287485333,"x":56},{"y":7541130.368633024,"x":57},{"y":8431389.990100507,"x":58},{"y":9510097.677690707,"x":59},{"y":10792893.92078663,"x":60},{"y":12289850.760362346,"x":61},{"y":14002646.547108902,"x":62},{"y":15921782.088635033,"x":63},{"y":18024322.96253122,"x":64},{"y":20272705.102573548,"x":65},{"y":22615087.417131186,"x":66},{"y":24987559.125425957,"x":67},{"y":27318225.737307023,"x":68},{"y":29532856.06498559,"x":69},{"y":31561448.969722446,"x":70},{"y":33344854.331612166,"x":71},{"y":34840521.1645332,"x":72},{"y":36026570.94154594,"x":73},{"y":36903681.78982424,"x":74},{"y":37494652.71002407,"x":75},{"y":37841906.915202826,"x":76},{"y":38003503.31943987,"x":77},{"y":38048395.163054265,"x":78},{"y":38051684.685688086,"x":79},{"y":38090492.56546585,"x":80},{"y":38240838.79254113,"x":81},{"y":38575676.60583089,"x":82},{"y":39163985.50221058,"x":83},{"y":40070648.020320304,"x":84},{"y":41356722.53297575,"x":85},{"y":43079679.09854082,"x":86},{"y":45293178.01849606,"x":87},{"y":48046031.73970453,"x":88},{"y":51380095.703781836,"x":89},{"y":55326983.23793943,"x":90},{"y":59903694.46254657,"x":91},{"y":65107483.03306482,"x":92},{"y":70910536.10501133,"x":93},{"y":77255272.31570514,"x":94},{"y":84051214.21437812,"x":95},{"y":91174405.3033172,"x":96},{"y":98470170.87157407,"x":97},{"y":105759652.43092228,"x":98},{"y":112850011.91144082,"x":99},{"y":119547588.30959867,"x":100}],"hoverBorderColor":"rgba(48,152,42,1)","borderColor":"rgba(51,160,44,1)","hoverBackgroundColor":"rgba(48,152,42,0.5)","backgroundColor":"rgba(51,160,44,0.3)","clip":5,"fill":false},{"pointRadius":0,"label":"Set 5","showLine":true,"data":[{"y":0,"x":0},{"y":31.471261917722803,"x":1},{"y":958.0453938755321,"x":2},{"y":6695.964515576942,"x":3},{"y":25135.503163524412,"x":4},{"y":66172.02467760195,"x":5},{"y":137665.72703974097,"x":6},{"y":241380.0460994624,"x":7},{"y":370988.6417568756,"x":8},{"y":513172.090089757,"x":9},{"y":651314.3335779334,"x":10},{"y":770189.343197805,"x":11},{"y":859810.3759656417,"x":12},{"y":917254.2987667866,"x":13},{"y":946301.5242918055,"x":14},{"y":955592.3568240724,"x":15},{"y":956362.0515278014,"x":16},{"y":960681.9552717776,"x":17},{"y":980737.4480590275,"x":18},{"y":1029291.4831281697,"x":19},{"y":1121287.569688844,"x":20},{"y":1276566.3565429454,"x":21},{"y":1523831.3279512564,"x":22},{"y":1906183.4652654275,"x":23},{"y":2488620.0501287202,"x":24},{"y":3367712.1618495146,"x":25},{"y":4683079.806286673,"x":26},{"y":6629153.012933752,"x":27},{"y":9464081.694467574,"x":28},{"y":13510893.072797855,"x":29},{"y":19144853.5083871,"x":30},{"y":26761514.454794943,"x":31},{"y":36723022.26491157,"x":32},{"y":49286114.21328955,"x":33},{"y":64522704.3420468,"x":34},{"y":82250672.33136775,"x":35},{"y":101995384.31393243,"x":36},{"y":122999250.53092861,"x":37},{"y":144286916.508354,"x":38},{"y":164779777.14491242,"x":39},{"y":183439755.85905883,"x":40},{"y":199413501.0557896,"x":41},{"y":212147553.6446148,"x":42},{"y":221452906.05437374,"x":43},{"y":227510920.0527154,"x":44},{"y":230827182.27326536,"x":45},{"y":232151026.59718046,"x":46},{"y":232383385.57166055,"x":47},{"y":232494089.53785717,"x":48},{"y":233463555.23897904,"x":49},{"y":236255806.72859365,"x":50},{"y":241822491.47359434,"x":51},{"y":251132452.38209534,"x":52},{"y":265218686.97842517,"x":53},{"y":285233430.0285017,"x":54},{"y":312501530.2294499,"x":55},{"y":348561329.8437714,"x":56},{"y":395180549.69387984,"x":57},{"y":454332675.5298912,"x":58},{"y":528118306.4929559,"x":59},{"y":618617762.3234696,"x":60},{"y":727667974.2986914,"x":61},{"y":856569602.2431115,"x":62},{"y":1005748965.7390612,"x":63},{"y":1174420708.8851445,"x":64},{"y":1360315443.824324,"x":65},{"y":1559544740.993018,"x":66},{"y":1766667393.0296726,"x":67},{"y":1974993232.1524982,"x":68},{"y":2177117210.3582206,"x":69},{"y":2365626445.409548,"x":70},{"y":2533879924.3139315,"x":71},{"y":2676737624.854196,"x":72},{"y":2791120966.9377985,"x":73},{"y":2876319469.7699423,"x":74},{"y":2934010536.893019,"x":75},{"y":2968016195.0918255,"x":76},{"y":2983867552.9807124,"x":77},{"y":2988274090.432991,"x":78},{"y":2988597037.7427664,"x":79},{"y":2992407509.52225,"x":80},{"y":3007178877.0762525,"x":81},{"y":3040128496.586763,"x":82},{"y":3098193949.0868144,"x":83},{"y":3188107502.7214837,"x":84},{"y":3316520168.72513,"x":85},{"y":3490121727.78258,"x":86},{"y":3715702997.452225,"x":87},{"y":4000109728.778907,"x":88},{"y":4350043862.754096,"x":89},{"y":4771679197.344335,"x":90},{"y":5270077593.120009,"x":91},{"y":5848421069.712967,"x":92},{"y":6507114683.978246,"x":93},{"y":7242861150.549327,"x":94},{"y":8047852157.642091,"x":95},{"y":8909250581.452974,"x":96},{"y":9809138450.903429,"x":97},{"y":10725067115.375082,"x":98},{"y":11631266634.081158,"x":99},{"y":12500460845.875816,"x":100}],"hoverBorderColor":"rgba(250,135,134,1)","borderColor":"rgba(251,154,153,1)","hoverBackgroundColor":"rgba(250,135,134,0.5)","backgroundColor":"rgba(251,154,153,0.3)","clip":5,"fill":false}]}}
Code

{{Chart data|Chart data/doc examples|scatter}}

function p.scatter()
    local plot = chart.newChart{ type = 'scatter' }
        :setDimensions( '10vw', '10vh', 300, 300, true )
        :setTitle( 'Scatter chart' )
        :setXLabel( 'x axis label' )
        :setYLabel( 'y axis label' )
        :setYAxisType( 'logarithmic' )

    for i = 1, 5 do
        local set = plot:newDataSet()
        set.data = chart.generateXYFromFunc( function(x) return (math.sin( x/5 ) * 5 + x)^i end, 0, 100 )
        set.label = 'Set ' .. i

        if i == 2 then
            set.fill = '+2'
        end
    end

    return plot
end

---@class chart
local chart = {}

---@class dataSet
local dataSet = {}

local libraryUtil = require( 'Module:libraryUtil' )
local rgba = require( 'Module:Rgba' )
local isEmpty = require( 'Module:Paramtest' ).is_empty
local arr = require( 'Module:Array' )
local colors = require( 'Module:Chart data/Colors' )
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti

---@alias xyData table<string, number>
---@alias xyDataSet xyData[]
---@alias dataArr number[]
---@alias options table<string, string|number|boolean|table>

---@param val any
---@param default any
---@return any
local function default( val, default )
    if val == nil or (type( val ) == 'string' and isEmpty( val )) then
        return default
    else
        return val
    end
end

---@param obj chart | dataSet
---@param options options
local function defaultOptions( obj, options )
     local function _setOptions( tbl, options )
        for k, v in pairs( options ) do
            if type( v ) == 'table' and type( tbl[k] ) == 'table' then
                _setOptions( tbl[k], v )
            else
                tbl[k] = default( tbl[k], v )
            end
        end
    end

    _setOptions( obj, options )
end

local function stripNonChartJsVariables( tbl )
    local stripVarNames = {
        colorPalette = true,
        backgroundAlpha = true,
        hoverLightenValue = true,
        hoverSaturateValue = true,
        hoverAlpha = true,
        widthVal = true,
        heightVal = true,
        flippedXY = true,
        parent = true
    }

    local function _strip( tbl )
        for k, v in pairs( tbl ) do
            if stripVarNames[k] then
                tbl[k] = nil
            elseif type( v ) == 'table' then
                _strip( v )
            end
        end
    end

    _strip( tbl )
end

---@param tbl table
---@param seen table | nil @Only for internal use
local function stripInvalidValues( tbl, seen )
    seen = seen or {}
    seen[tbl] = true

    for k, v in pairs( tbl ) do
        if type( k ) == 'table' or type( k ) == 'function' then
            tbl[k] = nil
        elseif type( v ) == 'function' then
            tbl[k] = nil
        elseif seen[v] then
            tbl[k] = nil
        elseif type( v ) == 'table' then
            local mt = getmetatable( v )
            if mt and mt.__tostring and mt ~= arr then
                tbl[k] = tostring( v )
            else
                stripInvalidValues( v, seen )
            end
        end
    end

    setmetatable( tbl, nil )
end


-- =====================
--      Chart class
-- =====================
local checkChartClass = libraryUtil.makeCheckClassFunction( 'Module:Chart data' , 'chart', chart, 'chart object' )
chart.rgba = rgba
chart.colorPalettes = {}
for _, colorPalette in ipairs(colors) do
	chart.colorPalettes[colorPalette.name] = arr.map(colorPalette, rgba.new)
end

function chart.main( frame )
    return chart._main( (frame:getParent() or frame).args )
end

---@param args table
---@return string
function chart._main( args )
    checkType( 'Module:Chart_data._main', 1, args, 'table' )

    local data = args

    if not data.isChartObj then
        local moduleName = args.dataModule or args[1]
        local funcName = args['function'] or args[2]

        if isEmpty( moduleName ) then
            error( 'Data module was not provided or is empty' )
        end

        if moduleName:find( '[Mm]odule:' ) == nil then
            moduleName = 'Module:' .. moduleName
        end

        if funcName then
            data = require( moduleName )[ funcName ]( args )

            assert( type( data )=='table', string.format(
                "Error: function '%s' from module '%s' returned an invalid type (table expected, got %s)",
                funcName, moduleName, type( data ) ) )

            if data.isChartObj and not data.isFinished then
                data:finish()
            end
        else
            data = mw.loadData( moduleName )
        end
    end

    local width = args.width or data.width or 'min(540px, 100%, 100vw - 2em)'
    local height = args.height or data.height or 'min(400px, 100vh - 2em)'
    local minWidth = args.minWidth or args.min_width or data.minWidth or '300px'
    local minHeight = args.minHeight or args.min_height or data.minHeight or '300px'

    return string.format(
        '<div class="rsw-chartjs rsw-chartjs-config tile" style="position:relative; margin:1em 0; width:%s; height:%s; min-width:%s; min-height:%s; max-width:unset;%s"><pre>%s</pre></div>',
        width,
        height,
        minWidth,
        minHeight,
        data.resizable and ' resize:both; overflow:hidden; padding:0 5px 5px 0;' or '',
        mw.text.jsonEncode( data )
    )
end

---@param ys number[]
---@param xs number[] | nil
---@return xyDataSet
function chart.convertToXYFormat( ys, xs )
    checkType( 'Module:Chart_data.convertToXYFormat', 1, ys, 'table' )
    checkType( 'Module:Chart_data.convertToXYFormat', 2, xs, 'table', true )

    xs = xs or {}
    local ret = {}

    for i,v in ipairs( ys ) do
        table.insert( ret, { x=(xs[i] or i), y=v } )
    end

    return ret
end

---@param func function
---@param start_x number
---@param end_x number
---@param step number?
---@return xyDataSet
function chart.generateXYFromFunc( func, start_x, end_x, step )
    checkType( 'Module:Chart_data.generateXYFromFunc', 1, func, 'function' )
    checkType( 'Module:Chart_data.generateXYFromFunc', 2, start_x, 'number' )
    checkType( 'Module:Chart_data.generateXYFromFunc', 3, end_x, 'number' )
    checkType( 'Module:Chart_data.generateXYFromFunc', 4, step, 'number',  true )

    step = step or 1
    local ret = {}

    for i = start_x, end_x, step do
        table.insert( ret, { x=i, y=func( i ) } )
    end

    return ret
end

---@param low_chance number
---@param high_chance number
---@param start_level number
---@param end_level number
---@return xyDataSet
function chart.jagexInterpolation( low_chance, high_chance, start_level, end_level )
    checkType( 'Module:Chart_data.jagexInterpolation', 1, low_chance, 'number' )
    checkType( 'Module:Chart_data.jagexInterpolation', 2, high_chance, 'number' )
    checkType( 'Module:Chart_data.jagexInterpolation', 3, start_level, 'number' )
    checkType( 'Module:Chart_data.jagexInterpolation', 4, end_level, 'number' )

    local function interpolate( x )
        return math.floor( ( (99-x)*low_chance + (x-1)*high_chance ) / 98 )
    end

    return chart.generateXYFromFunc( interpolate, start_level, end_level )
end

---@param setup options
---@return chart
function chart.newChart( setup )
    checkType( 'Module:Chart_data.newChart', 1, setup, 'table', true )
    local obj = setup or {}

    if obj.type == 'bar' then
        defaultOptions( obj, {
            options = {
                fill = true,
                backgroundAlpha = 0.4,
                hoverLightenValue = 0.95,
                hoverAlpha = 0.5,
                hoverSaturateValue = 1,
                scales = {
                    x = { -- This is used for horizontal bar graphs
                        ticks = {
                            beginAtZero = true
                        }
                    },
                    y = {
                        ticks = {
                            beginAtZero = true
                        }
                    }
                }
            }
        } )
    elseif obj.type == 'bubble' then
        defaultOptions( obj, {
            options = {
                fill = true,
                backgroundAlpha = 0.4,
                hoverLightenValue = 0.95,
                hoverAlpha = 0.5,
                hoverSaturateValue = 1
            }
        } )
    elseif obj.type == 'radar' then
        defaultOptions( obj, {
            options = {
                scale = {
                    ticks = {
                        showLabelBackdrop = false,
                        z = 1
                    }
                }
            }
        } )
    elseif obj.type == 'pie' or obj.type == 'doughnut' then
        defaultOptions( obj, {
            options = {
                fill = true,
                backgroundAlpha = 0.8,
                hoverLightenValue = 0.95,
                hoverAlpha = 0.9,
                hoverSaturateValue = 1
            }
        } )
    elseif obj.type == 'polarArea' then
        defaultOptions( obj, {
            options = {
                fill = true,
                backgroundAlpha = 0.5,
                hoverLightenValue = 0.95,
                hoverAlpha = 0.6,
                hoverSaturateValue = 1,
                scale = {
                    ticks = {
                        showLabelBackdrop = false,
                        z = 1
                    }
                }
            }
        } )
    end

    defaultOptions( obj, {
        isChartObj = true,
        type = 'scatter',
        widthVal = 540,
        heightVal = 400,
        minWidth = 300,
        minHeight = 300,
        resizable = true,
        data = {
            datasets = {}
        },
        options = {
            fill = false,
            colorPalette = chart.colorPalettes.qualitative,
            backgroundAlpha = 0.3,
            hoverLightenValue = 0.95,
            hoverAlpha = 0.5,
            hoverSaturateValue = 1,
            maintainAspectRatio = false,
            title = {
                font = {
                    size = 18
                }
            },
            tooltips = {
                intersect = false
            },
        }
    } )

    setmetatable( obj, chart )

    obj:setDimensions( obj.widthVal, obj.heightVal, obj.minWidth, obj.minHeight, obj.resizable )

    return obj
end

---@vararg xyDataSet | dataArr
---@return chart
function chart:addDataSets( ... )
    checkChartClass( self, 'addDataSets' )
    local sets = { ... }

    for i, set in ipairs( sets ) do
        checkType( 'chart.addDataSets', i, set, 'table' )

        if not arr.contains( self.data.datasets, set, false ) then
            table.insert( self.data.datasets, set )
        end
    end

    return self
end

---@param labels string
---@return chart
function chart:addDataLabels( labels )
    checkChartClass( self, 'addDataLabels' )
    checkType( 'Module:Chart_data.addDataLabels', 1, labels, 'table' )

    self.data.labels = default( self.data.labels, {} )

    for _, label in ipairs( labels ) do
        table.insert( self.data.labels, label )
    end

    return self
end

---@param width number | string
---@param height number | string | nil
---@param minWidth number | string | nil
---@param minHeight number | string | nil
---@param resizable boolean | nil
---@return chart
function chart:setDimensions( width, height, minWidth, minHeight, resizable )
    checkChartClass( self, 'setDimensions' )
    checkTypeMulti( 'chart.setDimensions', 1, width, {'number', 'string'} )
    checkTypeMulti( 'chart.setDimensions', 2, height, {'number', 'string', 'nil'} )
    checkTypeMulti( 'chart.setDimensions', 3, minWidth, {'number', 'string', 'nil'} )
    checkTypeMulti( 'chart.setDimensions', 4, minHeight, {'number', 'string', 'nil'} )
    checkType( 'chart.setDimensions', 5, resizable, 'boolean', true )

    if type( width ) == 'number' then
        self.widthVal = width
        self.width = width .. 'px'
    elseif type( width ) == 'string' then
        self.width = width
        self.widthVal = tonumber( width:match( '%d+' ) )

        if type( self.widthVal ) ~= 'number' then
            error( "bad argument #1 to 'chart.setDimensions' (input doesn't contain a number)", 2 )
        end
    else
        self.widthVal = nil
        self.width = ''
    end

    if type( height ) == 'number' then
        self.heightVal = height
        self.height = height .. 'px'
    elseif type( height ) == 'string' then
        self.height = height
        self.heightVal = tonumber( height:match( '%d+' ) )

        if type( self.heightVal ) ~= 'number' then
            error( "bad argument #2 to 'chart.setDimensions' (input doesn't contain a number)", 2 )
        end
    else
        self.heightVal = nil
        self.height = ''
    end

    if type( minWidth ) == 'number' then
        self.minWidth = minWidth .. 'px'
    elseif type( minWidth ) == 'string' then
        self.minWidth = minWidth
    end

    if type( minHeight ) == 'number' then
        self.minHeight = minHeight .. 'px'
    elseif type( minHeight ) == 'string' then
        self.minHeight = minHeight
    end

    self.resizable = default( resizable, self.resizable )

    if arr.contains( {'pie', 'doughnut', 'radar', 'polarArea'}, self.type ) then
        self.height = self.width
        self.minHeight = self.minWidth
        self.options.aspectRatio = 1
    else
        if self.widthVal and self.heightVal then
            self.options.aspectRatio = self.widthVal / self.heightVal
        elseif self.widthVal then
            self.height = self.width
            self.options.aspectRatio = 1
        else
            self.options.aspectRatio = 1
        end
    end

	self.width = string.format( 'min(%s, 100%%, 100vw - 2em)', self.width )
    self.height = string.format( 'min(%s, 100vh - 2em)', self.height )

    return self
end

---@param text string | table | nil
---@param position string | nil
---@return chart
function chart:setTitle( text, position )
    checkChartClass( self, 'setTitle' )
    checkTypeMulti( 'chart.setTitle', 1, text, {'string', 'table', 'nil'} )
    checkType( 'chart.setTitle', 1, position, 'string', true )

    self:setOptions{
        title = {
            display = text and true or false,
            text = text,
            position = position or 'top'
        }
    }

    return self
end

---@param label string | nil
---@return chart
function chart:setXLabel( label )
    checkChartClass( self, 'setXLabel' )
    checkType( 'chart.setXLabel', 1, label, 'string', true )

    if arr.contains( {'line', 'bar', 'bubble', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                x = {
                    scaleLabel = {
                        display = label and true or false,
                        labelString = label
                    }
                }
            }
        }
    end

    return self
end

---@param label string | nil
---@return chart
function chart:setYLabel( label )
    checkChartClass( self, 'setYLabel' )
    checkType( 'chart.setYLabel', 1, label, 'string', true )

    if arr.contains( {'line', 'bar', 'bubble', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                y = {
                    scaleLabel = {
                        display = label and true or false,
                        labelString = label
                    }
                }
            }
        }
    end

    return self
end

---@param min number | nil
---@param max number | nil
---@param step number | nil
---@return chart
function chart:setXLimits( min, max, step )
    checkChartClass( self, 'setXLimits' )
    checkType( 'chart.setXLimits', 1, min, 'number', true )
    checkType( 'chart.setXLimits', 2, max, 'number', true )
    checkType( 'chart.setXLimits', 3, step, 'number', true )

    if arr.contains( {'bubble', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                x = {
                    min = min,
                    max = max,
                    ticks = {
                        stepSize = step
                    }
                }
            }
        }
    end

    return self
end

---@param min number | nil
---@param max number | nil
---@param step number | nil
---@return chart
function chart:setYLimits( min, max, step )
    checkChartClass( self, 'setYLimits' )
    checkType( 'chart.setYLimits', 1, min, 'number', true )
    checkType( 'chart.setYLimits', 2, max, 'number', true )
    checkType( 'chart.setYLimits', 3, step, 'number', true )

    if arr.contains( {'line', 'bar', 'bubble', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                y = {
                    min = min,
                    max = max,
                    ticks = {
                        stepSize = step
                    }
                }
            }
        }
    end

    return self
end

---@param format string
---@return chart
function chart:setYFormat( format )
    checkChartClass( self, 'setYFormat' )
    checkType( 'chart.setYFormat', 1, format, 'string', true )

    self:setOptions{
        scales = {
            y = {
                ticks = {
                    format = format
                }
            }
        }
    }

    return self
end

---@param format string
---@return chart
function chart:setXFormat( format )
    checkChartClass( self, 'setXFormat' )
    checkType( 'chart.setXFormat', 1, format, 'string', true )

    self:setOptions{
        scales = {
            x = {
                ticks = {
                    format = format
                }
            }
        }
    }

    return self
end

---@param min number | nil
---@param max number | nil
---@param step number | nil
---@return chart
function chart:setRadialLimits( min, max, step )
    checkChartClass( self, 'setRadialLimits' )
    checkType( 'chart.setRadialLimits', 1, min, 'number', true )
    checkType( 'chart.setRadialLimits', 2, max, 'number', true )
    checkType( 'chart.setRadialLimits', 3, step, 'number', true )

    if arr.contains( {'radar', 'polarArea'}, self.type ) then
        self:setOptions{
            scale = {
                min  = min,
                max = max,
                ticks = {
                    stepSize = step
                }
            }
        }
    end

    return self
end

---@param type string | nil
---@return chart
function chart:setXAxisType( type )
    checkChartClass( self, 'setXAxisType' )
    checkType( 'chart.setXAxisType', 1, type, 'string', true )

    if arr.contains( {'bar', 'bubble', 'line', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                x = {
                    type = type,
                    ticks = {
                        format = {
                            maximumSignificantDigits = (type == 'logarithmic') and 3 or nil
                        }
                    }
                }
            }
        }
    end

    return self
end

---@param type string | nil
---@return chart
function chart:setYAxisType( type )
    checkChartClass( self, 'setYAxisType' )
    checkType( 'chart.setYAxisType', 1, type, 'string', true )

    if arr.contains( {'bar', 'bubble', 'line', 'scatter'}, self.type ) then
        self:setOptions{
            scales = {
                y = {
                    type = type,
                    ticks = {
                        format = {
                            maximumSignificantDigits = (type == 'logarithmic') and 3 or nil
                        }
                    }
                }
            }
        }
    end

    return self
end

---@param val boolean
---@return chart
function chart:showLegend( val )
    checkChartClass( self, 'showLegend' )
    checkType( 'chart.showLegend', 1, val, 'boolean' )

    self:setOptions{
        legend = {
            display = val
        }
    }

    return self
end

---@param format string
---@return chart
function chart:setTooltipFormat( format )
    checkChartClass( self, 'setTooltipFormat' )
    checkType( 'chart.setTooltipFormat', 1, format, 'string', true )

    self:setOptions{
        tooltips = {
        	format = format
        }
    }

    return self
end

---@param count number
---@return chart
function chart:setDatasetsPerGroup( count )
    checkChartClass( self, 'setDatasetsPerGroup' )
    checkType( 'chart.setDatasetsPerGroup', 1, count, 'number', true )

    self:setOptions{
        datasetsPerGroup = count
    }

    return self
end

---@return chart
function chart:flipXY()
    checkChartClass( self, 'flipXY' )

    if self.type == 'bar' then
        self:setXAxisType( 'linear' )
            :setYAxisType( 'category' )
            :setOptions{
                scales = {
                    x = {
                        offset = false,
                        gridLines = {
                            offsetGridLines = false
                        }
                    }
                }
            }

        self.flippedXY = true

        for _, v in ipairs( self.data.datasets ) do
            v.indexAxis = 'y'
        end
    end

    return self
end

---@param options options
---@return chart
function chart:setOptions( options )
    checkChartClass( self, 'setOptions' )
    checkType( 'chart.setOptions', 1, options, 'table' )

    local function _setOptions( tbl, options )
        for k, v in pairs( options ) do
            if type( v ) == 'table' and type( tbl[k] ) == 'table' then
                _setOptions( tbl[k], v )
            else
                tbl[k] = v
            end
        end
    end

    _setOptions( self.options, options )

    return self
end

---@return string | table
function chart:finish()
    checkChartClass( self, 'finish' )

    for i, set in ipairs( self.data.datasets ) do
        if (self.options.colorPalette or set.colorPalette) and
            self.options.backgroundAlpha and
            self.options.hoverLightenValue and
            self.options.hoverSaturateValue and
            self.options.hoverAlpha
        then
            if type(set.baseColor) == 'string' then
                set.color = rgba.new(set.baseColor)
            end
            if type(set.color) == 'string' then
                set.color = rgba.new(set.color)
            end
            set.color = set.color or set.baseColor -- [[MediaWiki:Gadget-Charts-core.js]] uses baseColor instead of just color
            set.baseColor = set.color

            if arr.contains( {'bar', 'pie', 'doughnut', 'polarArea'}, self.type ) then
                if set.color and not set.colorPalette then
                    set.borderColor = tostring( set.color )
                    set.hoverBorderColor = tostring( set.color:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                              :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue ) )

                    set.backgroundColor = tostring( set.color:fade( set.backgroundAlpha or self.options.backgroundAlpha ) )
                    set.hoverBackgroundColor = tostring( set.color:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                                  :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue )
                                                                  :fade( set.hoverAlpha or self.options.hoverAlpha ) )
                else
                    set.borderColor = {}
                    set.hoverBorderColor = {}
                    set.backgroundColor = {}
                    set.hoverBackgroundColor = {}

                    local palette = default( set.colorPalette, self.options.colorPalette )

                    for j = 1, #set.data do
                        local currentColor = palette[j] or rgba.new(0, 0, 0)
                        table.insert( set.borderColor, tostring( currentColor ) )
                        table.insert( set.hoverBorderColor,
                                      tostring( currentColor:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                         :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue ) ) )

                        table.insert( set.backgroundColor, tostring( currentColor:fade( set.backgroundAlpha or self.options.backgroundAlpha ) ) )
                        table.insert( set.hoverBackgroundColor,
                                      tostring( currentColor:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                         :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue )
                                                         :fade( set.hoverAlpha or self.options.hoverAlpha ) ) )
                    end
                end
            else
                local currentDatasetGroupIndex = i
                if self.options.datasetsPerGroup then
                	currentDatasetGroupIndex = math.modf((i-1)/self.options.datasetsPerGroup)+1
                end
                local palette = set.colorPalette or self.options.colorPalette
                local currentColor = set.color or palette[currentDatasetGroupIndex] or rgba.new(0, 0, 0)
                set.borderColor = set.borderColor or currentColor

                if not set.hoverBorderColor then
                    set.hoverBorderColor = set.borderColor:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                          :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue )
                end

                set.backgroundColor = set.backgroundColor or currentColor:fade( set.backgroundAlpha or self.options.backgroundAlpha )

                if not set.hoverBackgroundColor then
                    set.hoverBackgroundColor = set.backgroundColor:lighten( set.hoverLightenValue or self.options.hoverLightenValue )
                                                                  :saturate( set.hoverSaturateValue or self.options.hoverSaturateValue )
                                                                  :fade( set.hoverAlpha or self.options.hoverAlpha )
                end

                set.fill = default( default( set.fill, self.options.fill ), false )
            end
        end
    end

    stripNonChartJsVariables( self )
    stripInvalidValues( self )
    self.isFinished =  true

    return self
end

---@return string
function chart:tostring()
    checkChartClass( self, 'tostring' )
    self:finish()
    return chart._main( self )
end

function chart:debug()
    checkChartClass( self, 'debug' )
    local temp = chart.__tostring  -- Prevent chart from being turned into a json
    chart.__tostring = nil
    mw.logObject( self )
    chart.__tostring = temp
end

chart.__index = chart
chart.__tostring = chart.tostring
chart.__concat = function( x, y )
    return tostring( x ) .. tostring( y )
end

-- =======================
--      DataSet class
-- =======================
local checkDataSetClass = libraryUtil.makeCheckClassFunction( 'Module:Chart data', 'dataSet', dataSet, 'dataSet object' )

---@param setup options
---@return dataSet
function chart:newDataSet( setup )
    checkChartClass( self, 'newDataSet' )
    checkType( 'chart.newDataSet', 1, setup, 'table', true )
    local obj = setup or {}

    if self.type == 'scatter'  then
        obj.showLine = default( obj.showLine, true )
        obj.pointRadius = default( obj.pointRadius, 0 )
    end

    if self.type == 'bar' then
        obj.borderWidth = default( obj.borderWidth, 1 )

        if self.flippedXY then
            obj.indexAxis = 'y'
        end
    end

    obj.data = default( obj.data, {} )
    obj.clip = 5
    obj.parent = self

    self:addDataSets( obj )

    return setmetatable( obj, dataSet )
end

---@param data xyDataSet | dataArr
---@return dataSet
function dataSet:addData( data )
    checkDataSetClass( self, 'addData' )
    checkType( 'dataSet.addData', 1, data, 'table' )

    for _, v in ipairs( data ) do
        table.insert( self.data, v )
    end

    return self
end

---@param data xyData | number
---@return dataSet
function dataSet:addDataPoint( data )
    checkDataSetClass( self, 'addDataPoint' )
    checkTypeMulti( 'dataSet.addDataPoint', 1, data, {'table', 'number'} )
    table.insert( self.data, data )

    return self
end

---@param options options
---@return dataSet
function dataSet:setOptions( options )
    checkDataSetClass( self, 'setOptions' )
    checkType( 'dataSet.setOptions', 1, options, 'table' )

    local function _setOptions( tbl, options )
        for k, v in pairs( options ) do
            if type( v ) == 'table' and type( tbl[k] ) == 'table' then
                _setOptions( tbl[k], v )
            else
                tbl[k] = v
            end
        end
    end

    _setOptions( self, options )

    return self
end

---@return chart
function dataSet:done()
    checkDataSetClass( self, 'done' )
    return self.parent
end

dataSet.__index = dataSet

return chart