public class SeriesWithPointLegendItems : Series, ISeries
{
object ISeries.GetLegendItemImageSource(int index, ref C1.Chart._Size imageSize)
{
{
imageSize.Height = 80;
imageSize.Width = 130;
SmartPhoneVendor vendor = vendors.ElementAt(index);
Bitmap bm = new Bitmap(Properties.Resources.US);
Image LegendIconImage = bm;
if (LegendIconImage != null && LegendIconImage.Width != 130)
{
Bitmap bmp = new Bitmap(130, 80);
using (SolidBrush sb = new SolidBrush(Color.White))
{
using (Graphics g = Graphics.FromImage(bmp))
{
Rectangle r = new Rectangle(0, 0, (int)imageSize.Width, (int)imageSize.Height);
using (Pen p = new Pen(sb))
{
g.DrawRectangle(p, r);
}
g.FillRectangle(new SolidBrush(Color.SkyBlue), r);
Point ci = new Point((int)(0.5 * Math.Abs(imageSize.Width - LegendIconImage.Width)),
(int)(0.5 * Math.Abs(imageSize.Height - LegendIconImage.Height)));
g.DrawImage(LegendIconImage, ci);
}
}
LegendIconImage = bmp;
}
Size bounds = this.Chart.ClientSize;
double divadj = (bounds.Height > 700) ? 5 : 11;
double fracHeight = bounds.Height / divadj;
if (fracHeight < imageSize.Height)
imageSize.Width = imageSize.Height = fracHeight;
return LegendIconImage;
}
}
}
Public Class SeriesWithPointLegendItems
Inherits Series
Implements ISeries
Private Function ISeries_GetLegendItemImageSource(index As Integer, ByRef imageSize As C1.Chart._Size) As Object Implements ISeries.GetLegendItemImageSource
If True Then
imageSize.Height = 80
imageSize.Width = 130
Dim vendor As SmartPhoneVendor = vendors.ElementAt(index)
Dim bm As New Bitmap(Sample10.Resources.US)
Dim LegendIconImage As Image = bm
If LegendIconImage IsNot Nothing AndAlso LegendIconImage.Width <> 130 Then
Dim bmp As New Bitmap(130, 80)
Using sb As New SolidBrush(Color.White)
Using g As Graphics = Graphics.FromImage(bmp)
Dim r As New Rectangle(0, 0, CInt(Math.Truncate(imageSize.Width)), CInt(Math.Truncate(imageSize.Height)))
Using p As New Pen(sb)
g.DrawRectangle(p, r)
End Using
g.FillRectangle(New SolidBrush(Color.SkyBlue), r)
Dim ci As Point = New Point(CInt((0.5 * Math.Abs(imageSize.Width - LegendIconImage.Width))), CInt((0.5 * Math.Abs(imageSize.Height - LegendIconImage.Height))))
g.DrawImage(LegendIconImage, ci)
End Using
End Using
LegendIconImage = bmp
End If
Dim bounds As Size = Me.Chart.ClientSize
Dim divadj As Double = If((bounds.Height > 700), 5, 11)
Dim fracHeight As Double = bounds.Height / divadj
If fracHeight < imageSize.Height Then
imageSize.Width = InlineAssignHelper(imageSize.Height, fracHeight)
End If
Return LegendIconImage
End If
End Function
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
target = value
Return value
End Function
End Class