HatchBrush sample code

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Madhur
Posts: 10
Joined: Thu Jul 10, 2014 5:00 pm

HatchBrush sample code

Post by Madhur » Wed Jul 30, 2014 3:35 pm

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.

ArctionJari

Re: HatchBrush sample code

Post by ArctionJari » Fri Aug 01, 2014 6:52 am

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;
}

Post Reply