Document Solutions for Excel, .NET Edition | Document Solutions
Features / Chart / Chart Types / Statistical Chart / Waterfall Chart
In This Topic
    Waterfall Chart
    In This Topic

    A waterfall chart shows the aggregate of values as they are added or subtracted.This type of chart is useful to understand how the initial value is affected by a series of positive and negative values.Waterfall charts can be used for viewing fluctuations in product earnings, net income or profit analysis.

    Using Code

    Refer the following code for adding Waterfall chart.

    C#
    Copy Code
      public void WaterfallChart()
      {
          // Initialize workbook
          Workbook workbook = new Workbook();
          // Fetch default worksheet 
          IWorksheet worksheet = workbook.Worksheets[0];
    
          // Prepare data for chart
          worksheet.Range["A1:B8"].Value = new object[,]
    {
         {"Starting Amt", 130},
         {"Measurement 1", 25},
         {"Measurement 2", -75},
         {"Subtotal", 80},
         {"Measurement 3", 45},
         {"Measurement 4", -65},
         {"Measurement 5", 80},
         {"Total", 140}
    };
          worksheet.Range["A:A"].Columns.AutoFit();
    
          // Add Waterfall Chart
          IShape waterfallChartShape = worksheet.Shapes.AddChart(ChartType.Waterfall, 300, 20, 300, 250);
          waterfallChartShape.Chart.SeriesCollection.Add(worksheet.Range["A1:B8"]);
    
          //Set subtotal & total points
          IPoints points = waterfallChartShape.Chart.SeriesCollection[0].Points;
          points[3].IsTotal = true;
          points[7].IsTotal = true;
    
          //Connector lines are not shown
          ISeries series = waterfallChartShape.Chart.SeriesCollection[0];
          series.ShowConnectorLines = false;
    
          // Configure Chart Title 
          waterfallChartShape.Chart.ChartTitle.Text = "Waterfall Chart";
    
          // Saving workbook to Xlsx
          workbook.Save(@"30-WaterfallChart.xlsx", SaveFileFormat.Xlsx);
      }