.net6 epplus图表之曲线操作

 


//图表
var chart = worksheet.Drawings.AddChart("chart", eChartType.LineMarkers);

for (int i = 0; i < rowCount; i++)
{
//折线,第一个参数:折线数据,第二个参数,x坐标数据
var chartSerie = chart.Series.Add(worksheet.Cells[startRow + i, startColumn, startRow + i, startColumn+ columnCount - 1], worksheet.Cells[7, startColumn,7, startColumn+ columnCount]);
//折线名称
chartSerie.HeaderAddress = worksheet.Cells[startRow + i, 6];
}

var chartWidth = (int)worksheet.Columns.Sum(s=>s.Width)/55;
var chartHeight = (int)worksheet.Rows.Sum(s=>s.Height)*5;
//图表宽高
chart.SetSize(chartWidth, chartHeight);
//图表位置
chart.SetPosition(chartHeight, 0);
//图表名称
chart.Title.Text = "水平位移观察曲线";
//y轴间隔
chart.YAxis.MinorUnit = 2;
//x轴显示位置
chart.XAxis.Crosses = eCrosses.Min;
//x轴辅助线
chart.XAxis.AddGridlines(true,true);
//折线样式
chart.StyleManager.SetChartStyle(ePresetChartStyle.LineChartStyle15);

posted @ 2024-09-19 14:09  元点  阅读(9)  评论(0编辑  收藏  举报