Reputation: 201
Platform : C# IDE: Microsoft Visual Studio 2010
I am trying to load marker image at a point in chart control from Resources path, but its not able to load the file path. Any suggestions ?
foreach (var pt in chart1.Series["Series1"].Points)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["OverNo"].Equals(pt.XValue) && Convert.ToInt32(dr["Fow"]) > 0)
{
// pt.XValue +=5;
if (Convert.ToInt32(dr["Fow"]) > 0)
{
//pt.MarkerImage = s + SC.whiteBall; // this works fine
//pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
if (Convert.ToInt32(dr["Fow"]) == 1)
{
// Bitmap b = new Bitmap(Properties.Resources.WhiteBall1);
pt.MarkerImage = s + SC.whiteBall;
pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
}
}
}
}
}
Error : ImageLoader - Cannot load image from this location: System.Drawing.Bitmap in Program.cs
Upvotes: 1
Views: 1973
Reputation: 1507
You can actually use an embedded resource, instead of a file copied to your output directory:
var myImage = new NamedImage("my_image_key", Properties.Resources.my_image);
myChartControl.Images.Add(myImage);
mySeries.MarkerImage = "my_image_key";
PS: Setting your resource file to Embedded Resource and the MarkerStyle to None seem optional.
Upvotes: 0
Reputation: 3025
MarkerImage
like MainApplicationPath\Images\yourImage.bmp. Check File.Exists
.MarkerImage
property on both data points and series. If you use a particular image for your data series all data points will inherit that. You can override it for specific data points.DeleteCustomProperty("MarkerImage")
and DeleteCustomProperty("MarkerStyle")
on your data points, then reset.Upvotes: 1