在 NPOI 条形图中将网格线添加到 y 轴
Add grid lines to y-axis in NPOI bar chart
我想向使用 NPOI 创建的条形图 (IChart) 添加水平网格线。我在文档中找不到任何关于向图表添加网格线的内容,我想知道我是否遗漏了什么。我的代码如下所示:
IDrawing drawing = sheet.CreateDrawingPatriarch();
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 4, chartRow, 10, chartRow + 30);
IChart chart = drawing.CreateChart(anchor);
IBarChartData<string, double> data = chart.ChartDataFactory.CreateBarChartData<string, double>();
IChartAxis xAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
xAxis.MajorTickMark = AxisTickMark.None;
xAxis.MinorTickMark = AxisTickMark.None;
IValueAxis yAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
yAxis.MajorTickMark = AxisTickMark.Cross;
yAxis.MinorTickMark = AxisTickMark.None;
yAxis.Crosses = AxisCrosses.AutoZero;
yAxis.SetCrossBetween(AxisCrossBetween.Between);
IChartDataSource<string> xSource = DataSources.FromStringCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 0, 0));
IChartDataSource<double> ySource = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 1, 1));
IBarChartSeries<string, double> series = data.AddSeries(xSource, ySource);
series.SetTitle("Matches By World-Check Category"); // This doesn't display for some reason
chart.Plot(data, xAxis, yAxis);
不支持显示图表的次要和主要网格线。
我建议创建一个 ticket 以进行增强。
我想向使用 NPOI 创建的条形图 (IChart) 添加水平网格线。我在文档中找不到任何关于向图表添加网格线的内容,我想知道我是否遗漏了什么。我的代码如下所示:
IDrawing drawing = sheet.CreateDrawingPatriarch();
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 4, chartRow, 10, chartRow + 30);
IChart chart = drawing.CreateChart(anchor);
IBarChartData<string, double> data = chart.ChartDataFactory.CreateBarChartData<string, double>();
IChartAxis xAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
xAxis.MajorTickMark = AxisTickMark.None;
xAxis.MinorTickMark = AxisTickMark.None;
IValueAxis yAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
yAxis.MajorTickMark = AxisTickMark.Cross;
yAxis.MinorTickMark = AxisTickMark.None;
yAxis.Crosses = AxisCrosses.AutoZero;
yAxis.SetCrossBetween(AxisCrossBetween.Between);
IChartDataSource<string> xSource = DataSources.FromStringCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 0, 0));
IChartDataSource<double> ySource = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(chartRow + 1, lastRow, 1, 1));
IBarChartSeries<string, double> series = data.AddSeries(xSource, ySource);
series.SetTitle("Matches By World-Check Category"); // This doesn't display for some reason
chart.Plot(data, xAxis, yAxis);
不支持显示图表的次要和主要网格线。
我建议创建一个 ticket 以进行增强。