简体   繁体   中英

How do I change a data label on an excel bar chart to inside base using EPPlus?

I have an ExcelBarChart that I am creating using EPPlus.

I'm trying to change the position of the data label to Inside Base, but when I look inside the ExcelBarChart object I see an ExcelChartDataLabel property, and inside that a property named eLabelPosition .

eLabelPosition is protected however and inaccessible.

What is the proper way to set the data label position using EPPlus?

Please see the relevant code below:

var chart = (ExcelBarChart)chartWorksheet.Drawings.AddChart("changesVisualized", eChartType.ColumnClustered);
chart.SetSize(1000, 500);
chart.SetPosition(0,0);
chart.Title.Text = row.Name + "Volume " + date1.ToString("MM/dd/yyyy") + " - " + date2.ToString("MM/dd/yyyy");
chart.DataLabel.ShowValue = true;

var thisYearSeries = (ExcelChartSerie)(chart.Series.Add(worksheet.Cells["B4,D4,F4,H4,J4"], worksheet.Cells["B3,D3,F3,H3,J3"]));
thisYearSeries.Header = "This Year's Volume";                   

var lastYearSeries = (ExcelChartSerie)(chart.Series.Add(chartWorksheet.Cells["A1,B1,C1,D1,E1"], worksheet.Cells["B3,D3,F3,H3,J3"]));
lastYearSeries.Header = "Last Year's Volume";

You can do something like this:

var barChart = worksheet.Drawings.AddChart("Chart1", eChartType.ColumnClustered);
barChart.SetPosition(data.Count + 1, 0, 0, 0);
barChart.Title.Text = "Test Chart";
barChart.Title.Font.Bold = true;
barChart.Title.Font.Size = 12;

var serie = barChart.Series.Add(worksheet.Cells[2, 2, data.Count + 1, 2], worksheet.Cells[2, 1, data.Count + 1, 1]);
var barSeries = (ExcelBarChartSerie)serie;
barSeries.DataLabel.Font.Bold = true;
barSeries.DataLabel.ShowValue = true;
barSeries.DataLabel.ShowPercent = true;
barSeries.DataLabel.ShowLeaderLines = true;
barSeries.DataLabel.Separator = ";";
barSeries.DataLabel.Position = eLabelPosition.InBase;

Adapted from my example here:

How do I modify a chart series using EPPLus?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM