Skip to content
ChartForgeX
Struct

ChartColor

ChartForgeX.Primitives

Namespace
ChartForgeX.Primitives
Assembly
ChartForgeX
Base
ValueType
Implements
IEquatable<ChartColor>
Modifiers
sealed

Represents an RGBA color with an optional page CSS custom property used by SVG rendering.

Inheritance

  • ValueType
  • ChartColor

Usage

Explore 1034 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 476

Accepted by parameters 558

Constructors

public ChartColor(byte r, byte g, byte b, byte a = 255) #

Initializes a new instance of the ChartColor struct.

Parameters

r byte required
The red channel.
g byte required
The green channel.
b byte required
The blue channel.
a byte = 255 optional
The alpha channel.

Methods

public void Deconstruct(out byte r, out byte g, out byte b, out byte a) #

Deconstructs the color into red, green, blue, and alpha channels.

Parameters

r byte required
The red channel.
g byte required
The green channel.
b byte required
The blue channel.
a byte required
The alpha channel.
Equals 2 overloads
public bool Equals(ChartColor other) #

Compares the channels and the CSS variable name.

Parameters

other ChartForgeX.Primitives.ChartColor required

Returns

bool
public override bool Equals(object? obj) #

Indicates whether this instance and a specified object are equal.

Parameters

obj object? required
The object to compare with the current instance.

Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.
FromArgb 3 overloads
public static ChartColor FromArgb(byte a, byte r, byte g, byte b) #

Creates a color from explicit alpha, red, green, and blue channels.

Parameters

a byte required
The alpha channel.
r byte required
The red channel.
g byte required
The green channel.
b byte required
The blue channel.

Returns

ChartColor A chart color.
public static ChartColor FromArgb(uint argb) #

Creates a color from a packed 0xAARRGGBB value.

Parameters

argb uint required
The packed ARGB color.

Returns

ChartColor A chart color.
public static ChartColor FromArgb(int argb) #

Creates a color from a packed 0xAARRGGBB value.

Parameters

argb int required
The packed ARGB color.

Returns

ChartColor A chart color.
public static ChartColor FromHex(string hex) #

Creates a color from #RGB, #RGBA, #RRGGBB, or #RRGGBBAA notation.

Parameters

hex string required
The hexadecimal color string.

Returns

ChartColor A chart color.
public static ChartColor FromRgb(byte r, byte g, byte b) #

Creates an opaque RGB color.

Parameters

r byte required
The red channel.
g byte required
The green channel.
b byte required
The blue channel.

Returns

ChartColor An opaque chart color.
FromRgba 2 overloads
public static ChartColor FromRgba(byte r, byte g, byte b, byte a) #

Creates a color with an explicit alpha channel.

Parameters

r byte required
The red channel.
g byte required
The green channel.
b byte required
The blue channel.
a byte required
The alpha channel.

Returns

ChartColor A chart color.
public static ChartColor FromRgba(uint rgba) #

Creates a color from a packed 0xRRGGBBAA value.

Parameters

rgba uint required
The packed RGBA color.

Returns

ChartColor A chart color.
public override int GetHashCode() #

Returns the hash code for this instance.

Returns

int A 32-bit signed integer that is the hash code for this instance.
public static bool op_Equality(ChartColor left, ChartColor right) #

Returns whether two colours are equal.

Parameters

left ChartForgeX.Primitives.ChartColor required
right ChartForgeX.Primitives.ChartColor required

Returns

bool
public static bool op_Inequality(ChartColor left, ChartColor right) #

Returns whether two colours differ.

Parameters

left ChartForgeX.Primitives.ChartColor required
right ChartForgeX.Primitives.ChartColor required

Returns

bool
public static ChartColor Parse(string value) #

Parses a named color or a hexadecimal color string.

Parameters

value string required
The named color or hexadecimal color string.

Returns

ChartColor A chart color.
public uint ToArgb() #

Converts the color to a packed 0xAARRGGBB value.

Returns

uint The packed ARGB color.
public int ToArgbInt32() #

Converts the color to a packed 0xAARRGGBB signed integer.

Returns

int The packed ARGB color as a signed integer.
public string ToCss() #

Converts the color to a CSS color string.

Returns

string A hexadecimal or rgba CSS color string, or the directly named custom property with its fallback.
public string ToHex() #

Converts the fallback color to a hexadecimal RGB string, without its CSS custom property.

Returns

string A CSS-compatible hexadecimal color string.
public string ToHexRgba() #

Converts the fallback color to a hexadecimal RGBA string, without its CSS custom property.

Returns

string A CSS-compatible hexadecimal color string with alpha.
public uint ToRgba() #

Converts the color to a packed 0xRRGGBBAA value.

Returns

uint The packed RGBA color.
public override string ToString() #

Returns the CSS form, the same as ChartColor.ToCss.

Returns

string
public static bool TryFromHex(string? hex, out ChartColor color) #

Attempts to create a color from #RGB, #RGBA, #RRGGBB, or #RRGGBBAA notation.

Parameters

hex string? required
The hexadecimal color string.
color ChartForgeX.Primitives.ChartColor required
The parsed chart color.

Returns

bool True when parsing succeeds.
public static bool TryParse(string? value, out ChartColor color) #

Attempts to parse a named color or a hexadecimal color string.

Parameters

value string? required
The named color or hexadecimal color string.
color ChartForgeX.Primitives.ChartColor required
The parsed chart color.

Returns

bool True when parsing succeeds.
public ChartColor WithAlpha(byte alpha) #

Creates a copy of this color with a different alpha channel, retaining its CSS custom property if present.

Parameters

alpha byte required
The alpha channel.

Returns

ChartColor A chart color with the requested alpha channel.
public ChartColor WithCssVariable(string name) #

Names a page color directly, retaining this color's channels as the raster and CSS fallback.

Parameters

name string required
A custom property name such as --accent, containing only ASCII letters, digits, underscores and hyphens after --.

Returns

ChartColor A color that keeps its custom property independently of other colors with the same fallback.

Exceptions

  • ArgumentException – The custom property name is invalid.
public ChartColor WithOpacity(double opacity) #

Creates a copy of this color with opacity expressed as a unit interval.

Parameters

opacity double required
The opacity from zero to one.

Returns

ChartColor A chart color with the requested opacity.

Properties

public string? CssVariable { get; } #

Gets the explicitly named CSS custom property, or null for a literal color.

public static ChartColor Transparent { get; } #

Gets a fully transparent color.

public static ChartColor White { get; } #

Gets opaque white.

public static ChartColor Black { get; } #

Gets opaque black.

Fields

public readonly byte R #

Gets the red channel.

public readonly byte G #

Gets the green channel.

public readonly byte B #

Gets the blue channel.

public readonly byte A #

Gets the alpha channel.