HatchBrush sample code
Moderator: Queue Moderators
HatchBrush sample code
wanted to set chart background patterns using WPF Lightning chart hatch brush, .NET Framework uses DrawingBrush, just wondering if we can get sample code for setting chart background using hatch brush.
Re: HatchBrush sample code
This code will work. It uses ZigZag hatch style for both chart and view area background.
Code: Select all
System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.ZigZag, System.Drawing.Color.Black, System.Drawing.Color.White);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(512, 512);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.Clear(System.Drawing.Color.White);
g.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, 512, 512));
}
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
// Set chart background.
ms.Position = 0;
m_chart.ChartBackground.Bitmap.Image = System.Windows.Media.Imaging.BitmapFrame.Create(ms);
m_chart.ChartBackground.Bitmap.Layout = BitmapFillLayout.Tile;
m_chart.ChartBackground.Style = RectFillStyle.Bitmap;
// Set view area background.
ms.Position = 0;
m_chart.ViewXY.GraphBackground.Bitmap.Image = System.Windows.Media.Imaging.BitmapFrame.Create(ms);
m_chart.ViewXY.GraphBackground.Bitmap.Layout = BitmapFillLayout.Tile;
m_chart.ViewXY.GraphBackground.Style = RectFillStyle.Bitmap;
}