Skip to content

Commit 0c75f8f

Browse files
committed
Add C# binding for Chart.Candlestick
1 parent 335c689 commit 0c75f8f

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,70 @@ public static GenericChart.GenericChart OHLC<OHLCType, XType, TextType>(
10371037
UseDefaults: UseDefaults.ToOption()
10381038
);
10391039

1040+
/// <summary>
1041+
/// Creates a candlestick chart.
1042+
///
1043+
/// The candlestick is a style of financial chart describing open, high, low and close for a given `x` coordinate (most likely time). The boxes represent the spread between the `open` and `close` values and the lines represent the spread between the `low` and `high` values Sample points where the close value is higher (lower) then the open value are called increasing (decreasing). By default, increasing candles are drawn in green whereas decreasing are drawn in red.
1044+
/// </summary>
1045+
/// <param name="open">Sets the open values.</param>
1046+
/// <param name="high">Sets the high values.</param>
1047+
/// <param name="low">Sets the low values.</param>
1048+
/// <param name="close">Sets the close values.</param>
1049+
/// <param name="x">Sets the x coordinates. If absent, linear coordinate will be generated.</param>
1050+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover.</param>
1051+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
1052+
/// <param name="Opacity">Sets the Opacity otf the trace.</param>
1053+
/// <param name="Text">Sets a text associated with each datum</param>
1054+
/// <param name="MultiText">Sets individual text for each datum</param>
1055+
/// <param name="Line">Sets the line of this trace.</param>
1056+
/// <param name="IncreasingColor">Sets the color of increasing values</param>
1057+
/// <param name="Increasing">Sets the style options of increasing values (use this for more finegrained control than the other increasing-associated arguments).</param>
1058+
/// <param name="DecreasingColor">Sets the color of decreasing values</param>
1059+
/// <param name="Decreasing">Sets the style options of decreasing values (use this for more finegrained control than the other increasing-associated arguments).</param>
1060+
/// <param name="WhiskerWidth">Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers are as wide as the box(es).</param>
1061+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
1062+
public static GenericChart.GenericChart Candlestick<OHLCType, XType, TextType>(
1063+
IEnumerable<OHLCType> open,
1064+
IEnumerable<OHLCType> high,
1065+
IEnumerable<OHLCType> low,
1066+
IEnumerable<OHLCType> close,
1067+
IEnumerable<XType> x,
1068+
Optional<string> Name = default,
1069+
Optional<bool> ShowLegend = default,
1070+
Optional<double> Opacity = default,
1071+
Optional<TextType> Text = default,
1072+
Optional<IEnumerable<TextType>> MultiText = default,
1073+
Optional<Line> Line = default,
1074+
Optional<Color> IncreasingColor = default,
1075+
Optional<FinanceMarker> Increasing = default,
1076+
Optional<Color> DecreasingColor = default,
1077+
Optional<FinanceMarker> Decreasing = default,
1078+
Optional<double> WhiskerWidth = default,
1079+
Optional<bool> UseDefaults = default
1080+
)
1081+
where OHLCType : IConvertible
1082+
where XType : IConvertible
1083+
where TextType : IConvertible
1084+
=>
1085+
Plotly.NET.Chart2D.Chart.Candlestick<OHLCType, OHLCType, OHLCType, OHLCType, XType, TextType>(
1086+
open: open,
1087+
high: high,
1088+
low: low,
1089+
close: close,
1090+
x: x,
1091+
Name: Name.ToOption(),
1092+
ShowLegend: ShowLegend.ToOption(),
1093+
Opacity: Opacity.ToOption(),
1094+
Text: Text.ToOption(),
1095+
MultiText: MultiText.ToOption(),
1096+
Line: Line.ToOption(),
1097+
IncreasingColor: IncreasingColor.ToOption(),
1098+
Increasing: Increasing.ToOption(),
1099+
DecreasingColor: DecreasingColor.ToOption(),
1100+
Decreasing: Decreasing.ToOption(),
1101+
WhiskerWidth: WhiskerWidth.ToOption(),
1102+
UseDefaults: UseDefaults.ToOption()
1103+
);
10401104
};
10411105

10421106
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,21 @@ static void Main(string[] args)
7878
).WithXAxisRangeSlider(
7979
rangeSlider: Plotly.NET.LayoutObjects.RangeSlider.init(
8080
Visible: false
81+
)),
82+
Chart.Candlestick<double,DateTime,string>(
83+
open: new double [] {1.2, 2.7},
84+
high: new double [] {1.8, 8.5},
85+
low: new double [] {0.5, 0.1},
86+
close: new double [] {1.1, 2.9},
87+
x: new DateTime [] {DateTime.Parse("07/07/2021"), DateTime.Parse("07/07/2022") }
88+
).WithXAxisRangeSlider(
89+
rangeSlider: Plotly.NET.LayoutObjects.RangeSlider.init(
90+
Visible: false
8191
)),
8292
Chart.Invisible(),
8393
Chart.Invisible(),
8494
Chart.Invisible(),
8595
Chart.Invisible(),
86-
Chart.Invisible(),
8796

8897
//3D traces
8998
Chart.Scatter3D<int,int,int,string>(

0 commit comments

Comments
 (0)