如何设置MS图表LegendItem图像大小
本文关键字:LegendItem 图表 图像 MS 何设置 设置 | 更新日期: 2023-09-27 18:17:03
我在WinForms中使用Image from Resources to LegendItem
var ImageName = "ImageName";
myChart.Images.Add(new NamedImage(ImageName, Resources.Image));
LegendItem legendItem = new LegendItem();
legendItem.Name = "legend text";
legendItem.Image = ImageName;
myChart.Legends[Legend.Name].CustomItems.Add(legendItem);
但是图像的大小太小了。我怎样才能改变呢?
在这种情况下您应该使用自定义的LegendCell。这意味着您要为LegendItem定义单元格,并指定它们的属性。像这样:
LegendItem legendItem = new LegendItem();
LegendCell cell1 = new LegendCell();
cell1.Name = "cell1";
cell1.Text = "legend text";
// here you can specify alignment, color, ..., too
LegendCell cell2 = new LegendCell();
cell2.Name = "cell2";
cell2.CellType = System.Windows.Forms.DataVisualization.Charting.LegendCellType.Image;
cell2.Image = "path of your img";
cell2.Size = new Size(.....);
legendItem.Cells.Add(cell1);
legendItem.Cells.Add(cell2);