Skip to main content

ChartTools Class

ChartTools provides a versatile collection of static utility methods used across various layout managers and components for math operations, grid manipulations, and cross-platform media helpers.

public class ChartTools

Example of usage in the code behind:

ChartTools.LoadImages(pathToFile);
// or
ChartTools.CalcGradient(toneColor, Color.Black, 65);

Public Methods​

AdjustBitmapAlpha (Desktop Only)​

Adjusts bitmap alpha to given level for every pixel. Doesn't modify the input bitmap.

public static Bitmap AdjustBitmapAlpha(Bitmap bitmapIn, int alpha);

Returns​

  • Description: Bitmap with selected alpha.

AntiAliasBitmap (Desktop Only)​

Anti-alias bitmap. Makes anti-aliasing for image, or blur-effect.

public static Bitmap AntiAliasBitmap(Bitmap bitmapIn, BitmapAntialiasOptions options);

Returns​

  • Description: Creates the correct size output bitmap and returns it. If invalid parameters are given, returns null.

BitmapFrameTo32BGRA (Desktop Only)​

Covert BitmapFrame to 32 BGRA.

public static BitmapFrame BitmapFrameTo32BGRA(BitmapFrame img);

Returns​

  • Description: 32BGRA BitmapFrame.

BitmapSegmentFromBitmap (Desktop Only)​

Get a segment (sub-region) of a bitmap.

public static Bitmap BitmapSegmentFromBitmap(Bitmap bitmapIn, int firstColumnIndex, int segmentWidth, int firstRowIndex, int segmentHeight);

Returns​

  • Description: Bitmap segment as a new bitmap.

CalcGradient​

Calculates the gradient color between two colors.

public static PublicColor CalcGradient(PublicColor colorFrom, PublicColor colorTo, double position percents);

Returns​

  • Description: Gradient color.

CalcPolygonArea​

Get polygon area.

public static double CalcPolygonArea(PointDouble2D[] points);

Returns​

  • Description: Area of polygon.

CalcPolygonCenterOfGravity​

Calculate center of gravity (centroid) of a homogenous polygon.

public static PointDouble2D CalcPolygonCenterOfGravity(PointDouble2D[] points);

Returns​

  • Description: Center of gravity point.

CalculateMapCoordSphericalAngles​

Calculate map coordinate spherical angles, phi and theta.

public static void CalculateMapCoordSphericalAngles(MapCoordinate coordinate, double sphereRadius,
out double phi, out double theta);

Returns / out​

  • Description: Phi angle in degrees and Theta angle in degrees.

CalculateMapDistance​

Calculate distance between two coordinates in world map, by using latitude and longitude.

public static double CalculateMapDistance(PointFloat coord1, PointFloat coord2);
public static double CalculateMapDistance(MapCoordinate coordinate1, MapCoordinate coordinate2);

Returns​

  • Description: Distance in kilometers.

CalculateSphereFullGreatCircleCoords​

Calculate great circle coords for sphere.

public static MapCoordinate[] CalculateSphereFullGreatCircleCoords(MapCoordinate beginPoint, MapCoordinate endPoint, double angleStep);

Returns​

  • Description: Array of MapCoordinate.

CalculateSphericalRoute​

Calculate a spherical route (going shortest way, in sphere surface). This is also known as Great Circle route.

public static MapCoordinate[] CalculateSphericalRoute(MapCoordinate beginPoint, MapCoordinate endPoint,
double sphereRadius, double angleStep);

Returns​

  • Description: Route waypoints.

CaptureControlToBitmap (Desktop Only)​

Captures a Control area to a bitmap, very fast. Great for making Chart, Any other Control, or Form capture into set of images.

public static Bitmap CaptureControlToBitmap(Control control);

Returns​

  • Description: Bitmap.

ColorHSVA​

Hue: angle of color circle where 0 deg = red, 120 deg = green, 240 deg = blue.
Saturation: defines the brilliance and intensity of a color. Default = 1, range = 0-1.
Value refers to the lightness or darkness of a color; default = 1, range = 0-1
Alpha describes the transparency; default = 1. range = 0-1.

public static PublicColor ColorHSVA(double hue, double saturation = 1, double value = 1, double alpha = 1);

ColorToInt​

Media color to integer. / Drawing color to integer.

public static int ColorToInt(PublicColor color);

Returns​

  • Description: Media color as ARGB value. / Drawing color as ARGB value.

ColorWithAlpha​

Create color from known color by given alpha value.

public static PublicColor ColorWithAlpha(PublicColor color, byte alpha);

Convert2DArrayTo1D​

Convert 2-dimensional array to 1-dimensional, row by row

public static T[] Convert2DArrayTo1D<T>(T[,] array) where T : struct;

Returns​

  • Description: 1D array

ConvertDataToColorsByFixedIntervalPalette​

Convert data values to colors, by given palette. Palette is defined by steps, consisting of value and corresponding color. E.g. 0 : Black, 50: Yellow, 100: Red. The output colors are interpolated based on their position between steps. E.g. in this example palette, data value 60 will be almost yellow, but a little bit blending with red.

public static int[] ConvertDataToColorsByFixedIntervalPalette(double[] dataValues, double[] paletteStepValues, PublicColor[] paletteStepColors);

Returns​

  • Description: Colors as ARGB integer values.

ConvertDoubleArrayToBitmap / ConvertDoubleArrayToIndexed8Bitmap​

Convert double array into colors, by using gradient fixed-interval palette. / Convert double array into Indexed8 bitmap, by using uniform fixed-interval palette. NOTE! Can't use more than 256 colors. If input contains more colors, last ones will be truncated.

// Double Array Variant
public static Bitmap ConvertDoubleArrayToBitmap(double[][] array, System.Drawing.Color[] colors, double minValue, double maxValue);
// Indexed8 Variant
public static Bitmap ConvertDoubleArrayToIndexed8Bitmap(double[][] array, System.Drawing.Color[] colors, double minValue, double maxValue);

Returns​

  • Description: Bitmap.

ConvertFromString​

Convert Hex to Winforms color / Convert Hex to UWP color / Convert Hex to Winforms color

public static PublicColor ConvertFromString(string hex);

Returns​

  • Description: Converted color. If unable to convert a color channel (a, r, g, b), returns 0 to that channel.

ConvertMapCoordDMSToDegrees​

Convert DMS (Degrees, minutes, seconds) value to decimal degrees value, with given post-fix (N,E,S,W). / Convert DMS (Degrees, minutes, seconds) value to decimal degrees value.

public static double ConvertMapCoordDMSToDegrees(uint degrees, uint arcMinutes, double arcSeconds, CoordPostfix postfix);
public static double ConvertMapCoordDMSToDegrees(int degrees, uint arcMinutes, double arcSeconds);

Returns​

  • Description: Degrees value.

ConvertMapCoordTo3DPointOnSphere​

Convert map coordinate to a point in 3D space. The 3D space has origin in (0,0,0).

public static PointDouble3D ConvertMapCoordTo3DPointOnSphere(MapCoordinate mapCoordinate, double sphereRadius);

Returns​

  • Description: 3D point.

ConvertTicksToSeconds​

Converts time ticks to seconds, accurately.

public static double ConvertTicksToSeconds(long ticks);

Returns​

  • Description: Seconds value.

ConvertImageToFormat32bppArgb (Desktop Only)​

Converts image format to 32 bits ARGB.

public static Image ConvertImageToFormat32bppArgb(Image sourceImage);

Returns​

  • Description: Image in 32bbArgb format.

CreateGrayscaleAlphaMap (Desktop Only)​

Create a grayscale bitmap of source bitmap's pixels' alpha level. White output pixel means A = 255, Black means A = 0, and grayscales values between them.

public static Bitmap CreateGrayscaleAlphaMap(Bitmap bitmapIn);

Returns​

  • Description: Bitmap having alpha RGB values as grayscale, and alpha 255 in each output pixel.

CreateMap​

Load all images from the folder and return them as texture map. / Create texture map packed for VolumeRendering.

public static BitmapFrame CreateMap(string filePath);
public static BitmapFrame CreateMap(BitmapFrame[] imgs);
public static BitmapFrame CreateMap(double[][][] data, System.Windows.Media.Color[] colors, double minValue, double maxValue);

Returns​

  • Description: Texture Map. / WriteableBitmap / Bitmap frame.

ExtractValues​

Create a jagged array of Intensity series data (IntensityPoint array). Extracts IntensityPoint.Value fields.

public static double[][] ExtractValues(IntensityPoint[,] data);

Returns​

  • Description: Values array.

GatherApplicationInformation​

Gathers various information for debugging purposes as a string and optionally saves the output to a text file. Gathered data (if GatherDataOptions is set to All): system information, LightningChart object information, list of running processes, DxDiag output, installed Windows hotfixes.

[SecurityCritical]
public static string GatherApplicationInformation(GatherDataOptions options, LightningChart chart = null, string path = null, string fileName = null);

Returns​

  • Description: The gathered data as a string.

GetAllControls (Desktop Only)​

Get all controls and its subcontrols

public static List<Control> GetAllControls(Control control, bool getSubControls);

Returns​

  • Description: List of controls

GetPixelColors (Desktop Only)​

Get pixel color of a bitmap. This is much faster method than calling GetPixel() separately for each pixel of a bitmap.

public static System.Drawing.Color[,] GetPixelColors(Bitmap bitmapIn);

Returns​

  • Description: Pixel colors as an array.

GetPixelWpfColors (WPF Only)​

Gets pixels of System.Drawing.Bitmap object in System.Windows.Media.Color two-dimensional array.

public static System.Windows.Media.Color[][] GetPixelWpfColors(Bitmap bitmapIn);

Returns​

  • Description: Two-dimensional System.Windows.Media.Color array.

Grib2WindCsvConverter -> ConvertToCsv​

Converts GRIB2 10-metre wind fields to x,y,U,V CSV without native dependencies. Supports product template 4.0, regular latitude/longitude template 3.0, and complex packing with spatial differencing (template 5.3). Bitmaps, embedded missing values and other templates are deliberately rejected. Format references: https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/

public static int ConvertToCsv(string gribPath, string csvPath, int longitudeCount = 0, int latitudeCount = 0);

Parameters​

ParameterTypeRequiredDescription
gribPathstringYesPath to the GRIB input file.
csvPathstringYesPath to the target CSV file.
longitudeCountintNoSample counts (e.g. 100). A zero count retains all points.
latitudeCountintNoSample counts (e.g. 50). A zero count retains all points.

Returns​

  • Type: int
  • Description: Returns the number of written vectors.

ImageFromAppContent (UWP Only)​

Read image file from application content. Will throw exception, if anything fails.

public async static Task<WriteableBitmap> ImageFromAppContent(string path);

Returns​

  • Description: WriteableBitmap

ImageFromResource / ImageFromResourceFullName (Desktop Only)​

Create image from assembly embedded resource. Includes assembly name in the beginning of resource name. / Create image from assembly embedded resource

public static Image ImageFromResource(string resourceName, Assembly resourceAssembly);
public static Image ImageFromResourceFullName(string fullyQualifiedName, Assembly resourceAssembly);

Returns​

  • Description: Image if success, else null / Image if success, otherwise null.

IntensityValuesToIntensityGridPoints​

Convert intensity values jagged array to intensity grid points. Fills IntensityPoint.Value fields only.

public static IntensityPoint[,] IntensityValuesToIntensityGridPoints(double[][] values);

Returns​

  • Description: Rectangular array of intensity points.

InterpolateBilinear​

Makes bilinear interpolation for given data array.

public static double[][] InterpolateBilinear(double[][] sourceArray, int factorX, int factorY);

Returns​

  • Description: Interpolated data array.

Is64BitProcess​

Find out if this process needs 64-bit DLLs.

public static bool Is64BitProcess();

Returns​

  • Description: True if 64-bit DLLs are needed. False if it's happy with 32-bit DLLs.

LoadImages​

Load images from folder and return them as array of Bitmap / WriteableBitmaps. Will throw exception, if anything fails.

public static Bitmap[] LoadImages(string folderName);

Returns​

  • Description: Array of WriteableBitmap objects in the given folder. / Array of images from folder.

MediaColorToDrawingColor​

(System.Windows.)Media color to (System.)Drawing color.

public static System.Drawing.Color MediaColorToDrawingColor(System.Windows.Media.Color color);

Returns​

  • Description: Media color as Drawing color.

Rotate3DCoordinate​

Rotate 3D coordinate with yaw - pitch - roll method.

public static PointDouble3D Rotate3DCoordinate(PointDouble3D point, double angleAboutXAxis, double angleAboutYAxis, double angleAboutZAxis);

Returns​

  • Description: Rotated coordinate.

RoundToNearestInterval​

Rounds the value to nearest multiple of Interval.

public static double RoundToNearestInterval(double value, double interval);

Returns​

  • Description: Nearest interval multiple.

SamePoint​

Test if two point equals.

public static bool SamePoint(PointFloat p1, PointFloat p2);

Returns​

  • Description: True is points are at about same locations.

ShowLoadedAssemblies (Desktop Only)​

Show list of loaded assemblies by this application in MessageBox.

public static void ShowLoadedAssemblies();

SolvePointBetweenPoints​

Solve point within a line going from Point1 to Point2.

public static bool SolvePointBetweenPoints(PointFloat point1, PointFloat point2, float distanceFromP1, out PointFloat result);
public static PointFloatXYZ SolvePointBetweenPoints(PointFloatXYZ point1, PointFloatXYZ point2, float fPointPositionFromP1);

Returns​

  • Description: Returns true if successfully solved (length is not 0). / Point in position.

WriteLog (Desktop Only)​

Write a string to log file. If second parameter is not given, then log file is c:\temp\LightningChartLog.txt.

public static void WriteLog(string entry);
public static void WriteLog(string entry, string fileName);

ZoomToDataAndLabelsArea​

Zoom to data and label area.

public static void ZoomToDataAndLabelsArea(LightningChart chart);