How to represent an image in a legend item in WinForms Chart?
In Syncfusion® WinForms Charts, the legend item icon can be represented using different shapes, series types, or images. The RepresentationType property is used to specify the type of representation for the icon in a legend item.
C#
//Assign X and Y axes
this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.Category;
this.chartControl1.PrimaryYAxis.ValueType = ChartValueType.Double;
//Configure the series
CategoryAxisDataBindModel dataSeriesModel = new CategoryAxisDataBindModel(dataSource);
dataSeriesModel.CategoryName = "Year";
dataSeriesModel.YNames = new string[] { "Sales" };
ChartSeries chartSeries = new ChartSeries("Sales");
chartSeries.CategoryModel = dataSeriesModel;
this.chartControl1.Series.Add(chartSeries);
//Update the image to the legend icon
ImageList imageList1 = new ImageList();
imageList1.ImageSize = new Size(100, 100);
imageList1.Images.Add(Image.FromFile("D:\\WinForms\\Winforms_Chart_VBSample\\images\\sales.png"));
chartSeries.Style.Images = new ChartImageCollection(this.imageList1.Images);
chartSeries.Style.ImageIndex = 0;
this.chartControl1.Legend.RepresentationType = ChartLegendRepresentationType.SeriesImage;
VB
'Assign the X and Y axies
columnChart.PrimaryXAxis.ValueType = ChartValueType.Category
columnChart.PrimaryYAxis.ValueType = ChartValueType.Double
'Configure the chart series
For Each salesdata In viewmodel.PlantDetails
chartseries1.Points.Add(salesdata.Year, salesdata.Sales)
Next
chartseries1.Style.DisplayText = True
chartseries1.Style.TextOrientation = ChartTextOrientation.Up
'Update the image to the legend icon
Dim imageList1 = New ImageList()
imageList1.ImageSize = New Size(100, 100)
imageList1.Images.Add(Image.FromFile("D:\\WinForms\\Winforms_Chart_Sample\\images\\sales.png"))
chartseries1.Style.Images = New ChartImageCollection(imageList1.Images)
chartseries1.Style.ImageIndex = 0
columnChart.Legend.RepresentationType = ChartLegendRepresentationType.SeriesImage
Output:
Conclusion
I hope you enjoyed learning about how to represent an image in a legend item in WinForms Chart.
You can refer to our WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Chart examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!