Skip to content

Commit ed35130

Browse files
committed
Add C# bindings fro Chart.Waterfall
1 parent 0c75f8f commit ed35130

2 files changed

Lines changed: 101 additions & 2 deletions

File tree

src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,94 @@ public static GenericChart.GenericChart Candlestick<OHLCType, XType, TextType>(
11011101
WhiskerWidth: WhiskerWidth.ToOption(),
11021102
UseDefaults: UseDefaults.ToOption()
11031103
);
1104+
/// <summary>
1105+
/// Creates a waterfall chart.
1106+
///
1107+
/// Waterfall charts are special bar charts that help visualizing the cumulative effect of sequentially introduced positive or negative values
1108+
/// </summary>
1109+
/// <param name="x">Sets the x coordinates of the plotted data.</param>
1110+
/// <param name="y">Sets the y coordinates of the plotted data.</param>
1111+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
1112+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
1113+
/// <param name="IncreasingColor">Sets the color of increasing values</param>
1114+
/// <param name="Increasing">Sets the style options of increasing values (use this for more finegrained control than the other increasing-associated arguments).</param>
1115+
/// <param name="DecreasingColor">Sets the color of decreasing values</param>
1116+
/// <param name="Decreasing">Sets the style options of decreasing values (use this for more finegrained control than the other increasing-associated arguments).</param>
1117+
/// <param name="TotalsColor">Sets the color of total values</param>
1118+
/// <param name="Totals">Sets the style options of total values (use this for more finegrained control than the other increasing-associated arguments).</param>
1119+
/// <param name="Base">Sets where the bar base is drawn (in position axis units).</param>
1120+
/// <param name="Width">Sets the bar width (in position axis units).</param>
1121+
/// <param name="MultiWidth">Sets the individual bar width of each datum (in position axis units).</param>
1122+
/// <param name="Opacity">Sets the opacity of the trace.</param>
1123+
/// <param name="Text">Sets a text associated with each datum</param>
1124+
/// <param name="MultiText">Sets individual text for each datum</param>
1125+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
1126+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
1127+
/// <param name="TextFont">Sets the font used for `text`.</param>
1128+
/// <param name="Connector">Sets the waterfall connector of this trace</param>
1129+
/// <param name="Measure">An array containing types of measures. By default the values are considered as 'relative'. However; it is possible to use 'total' to compute the sums. Also 'absolute' could be applied to reset the computed total or to declare an initial value where needed.</param>
1130+
/// <param name="AlignmentGroup">Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.</param>
1131+
/// <param name="OffsetGroup">Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.</param>
1132+
/// <param name="Orientation">Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used - including if `visible` is "legendonly" but not if it is `false`. Sets the stacking direction. With "v" ("h"), the y (x) values of subsequent traces are added. Also affects the default value of `fill`.</param>
1133+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
1134+
public static GenericChart.GenericChart Waterfall<XType, YType, TextType>(
1135+
IEnumerable<XType> x,
1136+
IEnumerable<YType> y,
1137+
Optional<string> Name = default,
1138+
Optional<bool> ShowLegend = default,
1139+
Optional<Color> IncreasingColor = default,
1140+
Optional<FinanceMarker> Increasing = default,
1141+
Optional<Color> DecreasingColor = default,
1142+
Optional<FinanceMarker> Decreasing = default,
1143+
Optional<Color> TotalsColor = default,
1144+
Optional<FinanceMarker> Totals = default,
1145+
Optional<double> Base = default,
1146+
Optional<double> Width = default,
1147+
Optional<IEnumerable<double>> MultiWidth = default,
1148+
Optional<double> Opacity = default,
1149+
Optional<TextType> Text = default,
1150+
Optional<IEnumerable<TextType>> MultiText = default,
1151+
Optional<StyleParam.TextPosition> TextPosition = default,
1152+
Optional<IEnumerable<StyleParam.TextPosition>> MultiTextPosition = default,
1153+
Optional<Font> TextFont = default,
1154+
Optional<WaterfallConnector> Connector = default,
1155+
Optional<IEnumerable<StyleParam.WaterfallMeasure>> Measure = default,
1156+
Optional<string> AlignmentGroup = default,
1157+
Optional<string> OffsetGroup = default,
1158+
Optional<StyleParam.Orientation> Orientation = default,
1159+
Optional<bool> UseDefaults = default
1160+
)
1161+
where XType : IConvertible
1162+
where YType : IConvertible
1163+
where TextType : IConvertible
1164+
=>
1165+
Plotly.NET.Chart2D.Chart.Waterfall<XType, YType, TextType>(
1166+
x: x,
1167+
y: y,
1168+
Name: Name.ToOption(),
1169+
ShowLegend: ShowLegend.ToOption(),
1170+
IncreasingColor: IncreasingColor.ToOption(),
1171+
Increasing: Increasing.ToOption(),
1172+
DecreasingColor: DecreasingColor.ToOption(),
1173+
Decreasing: Decreasing.ToOption(),
1174+
TotalsColor: TotalsColor.ToOption(),
1175+
Totals: Totals.ToOption(),
1176+
Base: Base.ToOption(),
1177+
Width: Width.ToOption(),
1178+
MultiWidth: MultiWidth.ToOption(),
1179+
Opacity: Opacity.ToOption(),
1180+
Text: Text.ToOption(),
1181+
MultiText: MultiText.ToOption(),
1182+
TextPosition: TextPosition.ToOption(),
1183+
MultiTextPosition: MultiTextPosition.ToOption(),
1184+
TextFont: TextFont.ToOption(),
1185+
Connector: Connector.ToOption(),
1186+
Measure: Measure.ToOption(),
1187+
AlignmentGroup: AlignmentGroup.ToOption(),
1188+
OffsetGroup: OffsetGroup.ToOption(),
1189+
Orientation: Orientation.ToOption(),
1190+
UseDefaults: UseDefaults.ToOption()
1191+
);
11041192
};
11051193

11061194
}

tests/Plotly.NET.Tests.CSharpConsole/Program.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void Main(string[] args)
7878
).WithXAxisRangeSlider(
7979
rangeSlider: Plotly.NET.LayoutObjects.RangeSlider.init(
8080
Visible: false
81-
)),
81+
)),
8282
Chart.Candlestick<double,DateTime,string>(
8383
open: new double [] {1.2, 2.7},
8484
high: new double [] {1.8, 8.5},
@@ -89,7 +89,18 @@ static void Main(string[] args)
8989
rangeSlider: Plotly.NET.LayoutObjects.RangeSlider.init(
9090
Visible: false
9191
)),
92-
Chart.Invisible(),
92+
Chart.Waterfall<string, int, string>(
93+
x: new string [] {"A", "B", "Net", "Purch", "Other", "Profit"},
94+
y: new int [] {60, 80, 0, -40, -20, 0},
95+
Measure: new Plotly.NET.StyleParam.WaterfallMeasure [] {
96+
Plotly.NET.StyleParam.WaterfallMeasure.Relative,
97+
Plotly.NET.StyleParam.WaterfallMeasure.Relative,
98+
Plotly.NET.StyleParam.WaterfallMeasure.Total,
99+
Plotly.NET.StyleParam.WaterfallMeasure.Relative,
100+
Plotly.NET.StyleParam.WaterfallMeasure.Relative,
101+
Plotly.NET.StyleParam.WaterfallMeasure.Total
102+
}
103+
),
93104
Chart.Invisible(),
94105
Chart.Invisible(),
95106
Chart.Invisible(),

0 commit comments

Comments
 (0)