使用Vb中的Epplus更改条形图的条形图大小

时间:2018-06-07 18:05:08

标签: excel-vba epplus vba excel

我是EPPlus的新手。我有以下代码生成条形图,其中条形大小根据行获取没有变化。如果只提供一个数据行,则会创建一个大条。如果我提供更多数据行,则更小的条形成。如何将其修复为单一尺寸?

Dim barChart1 As OfficeOpenXml.Drawing.Chart.ExcelBarChart = worksheet5.Drawings.AddChart("BarChart1", OfficeOpenXml.Drawing.Chart.eChartType.ColumnStacked)
        barChart1.Style = OfficeOpenXml.Drawing.Chart.eChartStyle.Style27

        Dim startColConsumable As String = "D"
        Dim startRangeCol As String = "B"
        Dim startColIndex As Integer = 10
        Dim endColIndex As Integer = totalRow - 1
        Dim endRangeCol As String = "C"
        Dim startColUncommitted As String = "I"



        Dim consumableSeries As OfficeOpenXml.Drawing.Chart.ExcelBarChartSerie = barChart1.Series.Add(worksheet.Cells(String.Concat(startColConsumable, startColIndex.ToString(), ":", startColConsumable, endColIndex.ToString())), worksheet.Cells(String.Concat(startRangeCol, startColIndex.ToString(), ":", endRangeCol, endColIndex.ToString())))
        Dim uncommittedSeries As OfficeOpenXml.Drawing.Chart.ExcelBarChartSerie = barChart1.Series.Add(worksheet.Cells(String.Concat(startColUncommitted, startColIndex.ToString(), ":", startColUncommitted, endColIndex.ToString())), worksheet.Cells(String.Concat(startRangeCol, startColIndex.ToString(), ":", endRangeCol, endColIndex.ToString())))

        consumableSeries.Header = "Current FY V0 Consumable"
        consumableSeries.Fill.Color = System.Drawing.Color.FromArgb(204, 51, 0)
        consumableSeries.DataLabel.ShowValue = True
        'consumableSeries.DataLabel.ShowLeaderLines = True

        uncommittedSeries.Header = "Current FY V0 Uncommitted"
        uncommittedSeries.Fill.Color = System.Drawing.Color.FromArgb(51, 153, 255)
        uncommittedSeries.DataLabel.ShowValue = True
        'uncommittedSeries.DataLabel.ShowLeaderLines = True

        barChart1.Title.Text = "FY 2018 Consumable vs Uncommitted"
        barChart1.SetPosition(4, 4, 4, 4)
        barChart1.XAxis.Title.Text = "Func Area 5 and Fund Center"
        barChart1.YAxis.Title.Text = "Amount"
        barChart1.XAxis.Title.Font.Size = "15"
        barChart1.YAxis.Title.Font.Size = "15"
        barChart1.DataLabel.ShowPercent = True
        barChart1.SetSize(1540, 880) // fixed chart size
        barChart1.DataLabel.ShowValue = True
        barChart1.DataLabel.ShowLeaderLines = True
        barChart1.DataLabel.Separator = ";"

        barChart1.GapWidth = 40 'space between adjacent bars

            End If

提前致谢。

1 个答案:

答案 0 :(得分:0)

我尝试更改情节区域:这对我有所帮助。

If worksheet.Cells(String.Concat(startColConsumable, startColIndex.ToString(), ":", startColConsumable, endColIndex.ToString())).Count = 1 Then
            barChart1.SetSize(500, 880)
        ElseIf worksheet.Cells(String.Concat(startColConsumable, startColIndex.ToString(), ":", startColConsumable, endColIndex.ToString())).Count = 2 Then
            barChart1.SetSize(700, 880)
end if