Categories &

Functions List

Class Definition: Color

chartjs: obj = Color (value)

A class for creating Chart.js compatible Color objects.

obj = Color (value) returns a Color object defined by value, which can either be a character vector, a cellstring array, a numeric matrix, or a cell matrix containing the following combinations. Each Color object only applies to a given dataset. If you want to pass different color patterns to multiple datasets when constructing a Chart object, then you need to pass a Color object array to the Chart’s constructor.

When value is character vector, it can define a single color either by using one of the acceptable color names given below or by using hexadecimal string values in the forms #FFFFFF and #FFFFFFFF. The former defines an RGB color space, whereas the later defines an RGBA color space that includes transparency.

Valid color names are:

  • beige
  • black
  • blue, lightblue, darkblue
  • brown
  • coral, lightcoral
  • cyan, darkcyan
  • green, lightgreen, darkgreen
  • gray, grey, lightgray, lightgrey, darkgray, darkgrey
  • magenta, darkmagenta
  • pink
  • red, darkred
  • white
  • yellow, lightyellow

If you want to apply multiple colors to a given dataset, then you can use a cellstring array whose elements follow the requirements for character vector values described above. The cellstring array must be a vector and its elements can interchangeably contain known color names or hexadecimal color values.

If value is a numeric, it follows Octave’s native RGB tripplet syntax. An RGB triplet is a 1×3 vector where each value is between 0 and 1 inclusive. The first value represents the percentage of Red, the second value the percentage of Green, and the third value the percentage of Blue. This syntax is also extended to support RGBA quadruplets, in which case the fourth value (also between 0 and 1 inclusive) of the 1×4 vector represents the transparency. If you want to apply multiple colors to a given dataset, then you can pass a numeric matrix of N×3 or N×4 size with each row representing a distinct RGB tripplet or RGBA quadruplet, respectively.

Alternatively you can define value as a cell array with two elements or an N×2 cell matrix in case you need to specify multiple colors in the same dataset. The first element of each row represents a color space name, which can be any of the four available choices: rgb, rgba, hsl, and hsla. The second element of each row must be a numeric 1×3 vector for rgb and hsl color spaces, or a numeric 1×4 vector for rgba and hsla color spaces. When assigning color value(s) as a cell array, the RGB values must be between 0 and 255 inclusive, the hue value must be between 0 and 360 inclusive, the saturation and lightness values must be percentages between 0 and 100 inclusive, whereas the alpha value must be between 0 and 1 inclusive. All numeric values except for the transparency are expected to be integer values, otherwise they are rounded to the nearest integer.

See also: BarChart, BarData, BubbleChart, BubbleData, DoughnutChart, DoughnutData, LineChart, LineData, PieChart, PieData, PolarAreaChart, PolarAreaData, RadarChart, RadarData, ScatterChart, ScatterData

Source Code: Color

Method: jsonstring

Color: json = jsonstring (obj)

Generate the JSON string of a Color object.

jsonstring (obj) returns a character vector, json, describing the context of the Color object in json format.

See also: Color, Fill