Setting Background Image for Bar chart

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

Setting Background Image for Bar chart

Post by Madhur » Thu Jul 10, 2014 5:06 pm

I've just started using Lightning Charts, wanted to set background image for barchart, it is setting for full graph, but wanted to set only for ViewXY.
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", UriKind.RelativeOrAbsolute));
brush.Stretch = Stretch.UniformToFill;
m_chart.Background = brush;
I want to set for m_chart.ViewXY.GraphBackground.Bitmap.Image

Thank you for your help!!

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Setting Background Image for Bar chart

Post by ArctionPasi » Thu Jul 10, 2014 7:02 pm

Hi Madhur,

LC has own classes for fills, because it uses lower level DirectX rendering than WPF graphics API.

set

Code: Select all


chart.ViewXY.GraphBackground.Bitmap.Image = BitmapFrame.Create(new Uri(@"C:\temp\pic.jpg", UriKind.RelativeOrAbsolute));
chart.ViewXY.GraphBackground.Bitmap.Layout = BitmapFillLayout.Stretch;
chart.ViewXY.GraphBackground.Style = RectFillStyle.Bitmap;

Then only the ViewXY graph area gets filled with the stretched bitmap.
LightningChart Support Team, PT

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

Re: Setting Background Image for Bar chart

Post by Madhur » Thu Jul 17, 2014 6:27 pm

Thanks Pasi!! It works!!
I want to use image from resources
ChartTools.ImageFromResource(Properties.Resources.MarketStrikeChartBGImage.ToString(), System.Reflection.Assembly.GetExecutingAssembly()); instead of BitmapFrame.Create(new Uri(@"Penguins.jpg", UriKind.RelativeOrAbsolute));
But when I use ChartTools.ImageFromResource function it gives message that it can't change from BitmapFrame to System.drawing.image

thanks in advance!!!

ArctionJari

Re: Setting Background Image for Bar chart

Post by ArctionJari » Fri Jul 18, 2014 4:09 pm

Here's a couple of code snippets you might find usefull:

Code: Select all

using (Stream stream = Application.GetResourceStream(new Uri("Images/NotPass.png", UriKind.Relative)).Stream)
{
    BitmapFrame bf = BitmapFrame.Create(stream);
}

Code: Select all

System.Drawing.Image img = ChartTools.ImageFromResource("Resources.Water75x75.png", System.Reflection.Assembly.GetExecutingAssembly());
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
	img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
	ms.Position = 0;

	BitmapFrame bf = System.Windows.Media.Imaging.BitmapFrame.Create(ms);
}
I hope these help. :)

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

Re: Setting Background Image for Bar chart

Post by Madhur » Fri Jul 18, 2014 5:45 pm

Thanks for response!!
I'm trying following code and it is not working, Not sure what is missing.
System.Drawing.Image img = ChartTools.ImageFromResource(Properties.Resources.WaterBubble.ToString(), System.Reflection.Assembly.GetExecutingAssembly());
BitmapFrame bf;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Position = 0;

bf = System.Windows.Media.Imaging.BitmapFrame.Create(ms);

}

m_chart.ViewXY.GraphBackground.Bitmap.Image = bf;

ArctionJari

Re: Setting Background Image for Bar chart

Post by ArctionJari » Mon Jul 21, 2014 8:52 am

Is your image file set as "Embedded Resource" (Build Action property)? Only difference compared to my code is that I'm setting Bitmap.Image property inside the "using" block. It shouldn't matter, though.

Does it throw an exception? If it does, what does it say?

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

Re: Setting Background Image for Bar chart

Post by Madhur » Mon Jul 21, 2014 6:43 pm

Thanks Jari!!
Is your image file set as "Embedded Resource" (Build Action property)?
No..it was not set...but after setting also it was not coming then found following issue
It was not accepting Properties.Resources.WaterBubble and Resources.WaterBubble...

then changed to Resources.WaterBubble.png, now it is able to display image.
Not sure the way it works for resources (it should get file name from embedded image resource but not!!)

thanks,
Madhur

Post Reply