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!!
Setting Background Image for Bar chart
Moderator: Queue Moderators
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Setting Background Image for Bar chart
Hi Madhur,
LC has own classes for fills, because it uses lower level DirectX rendering than WPF graphics API.
set
Then only the ViewXY graph area gets filled with the stretched bitmap.
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;
LightningChart Support Team, PT
Re: Setting Background Image for Bar chart
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!!!
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!!!
Re: Setting Background Image for Bar chart
Here's a couple of code snippets you might find usefull:
I hope these help.
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);
}
Re: Setting Background Image for Bar chart
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;
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;
Re: Setting Background Image for Bar chart
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?
Does it throw an exception? If it does, what does it say?
Re: Setting Background Image for Bar chart
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
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