Skip to content

Commit 3e8023e

Browse files
committed
Add Chart.Bar and Chart.Column C# bindings
1 parent 0c6444d commit 3e8023e

File tree

2 files changed

+177
-3
lines changed

2 files changed

+177
-3
lines changed

Diff for: src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

+152
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,157 @@ public static GenericChart.GenericChart Line<XType, YType, TextType>(
284284
UseDefaults: Helpers.ToOptionV(UseDefaults)
285285
);
286286

287+
/// <summary>
288+
/// Creates a bar chart, with bars plotted horizontally
289+
///
290+
/// A bar chart is a chart that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent.
291+
/// </summary>
292+
/// <param name="values">Sets the values that are plotted as the size of each bar.</param>
293+
/// <param name="Keys">Sets the keys associated with each bar.</param>
294+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
295+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
296+
/// <param name="Opacity">Sets the Opacity of the trace.</param>
297+
/// <param name="MultiOpacity">Sets the Opacity of each individual bar.</param>
298+
/// <param name="Text">Sets a text associated with each datum</param>
299+
/// <param name="MultiText">Sets individual text for each datum</param>
300+
/// <param name="MarkerColor">Sets the color of the bars</param>
301+
/// <param name="MarkerColorScale">Sets the colorscale for the bars. To have an effect, `MarkerColor` must map to color scale values.</param>
302+
/// <param name="MarkerOutline">Sets the color of the bar outlines</param>
303+
/// <param name="MarkerPatternShape">Sets a pattern shape for all bars</param>
304+
/// <param name="MultiMarkerPatternShape">Sets an individual pattern shape for each bar</param>
305+
/// <param name="MarkerPattern">Sets the marker pattern (use this for more finegrained control than the other pattern-associated arguments).</param>
306+
/// <param name="Marker">Sets the marker for the bars (use this for more finegrained control than the other marker-associated arguments).</param>
307+
/// <param name="Base">Sets where the bar base is drawn (in position axis units).</param>
308+
/// <param name="Width">Sets the bar width (in position axis units) of all bars.</param>
309+
/// <param name="MultiWidth">Sets the individual bar width (in position axis units) for each bar.</param>
310+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
311+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
312+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
313+
public static GenericChart.GenericChart Bar<ValuesType, KeysType, TextType>(
314+
IEnumerable<ValuesType> values,
315+
IEnumerable<KeysType>? Keys = null,
316+
string? Name = null,
317+
bool? ShowLegend = null,
318+
double? Opacity = null,
319+
IEnumerable<double>? MultiOpacity = null,
320+
TextType? Text = null,
321+
IEnumerable<TextType>? MultiText = null,
322+
Color? MarkerColor = null,
323+
StyleParam.Colorscale? MarkerColorScale = null,
324+
Line? MarkerOutline = null,
325+
StyleParam.PatternShape? MarkerPatternShape = null,
326+
IEnumerable<StyleParam.PatternShape>? MultiMarkerPatternShape = null,
327+
Pattern? MarkerPattern = null,
328+
Marker? Marker = null,
329+
IConvertible? Base = null,
330+
IConvertible? Width = null,
331+
IEnumerable<IConvertible>? MultiWidth = null,
332+
StyleParam.TextPosition? TextPosition = null,
333+
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
334+
bool? UseDefaults = null
335+
)
336+
where ValuesType : IConvertible
337+
where KeysType : IConvertible
338+
where TextType: class, IConvertible
339+
=>
340+
Plotly.NET.Chart2D.Chart.Bar<ValuesType, KeysType, TextType, IConvertible, IConvertible>(
341+
values: values,
342+
Keys: Keys.ToOption(),
343+
Name: Name.ToOption(),
344+
ShowLegend: ShowLegend.ToOptionV(),
345+
Opacity: Opacity.ToOptionV(),
346+
MultiOpacity: MultiOpacity.ToOption(),
347+
Text: Text.ToOption(),
348+
MultiText: MultiText.ToOption(),
349+
MarkerColor: MarkerColor.ToOption(),
350+
MarkerColorScale: MarkerColorScale.ToOption(),
351+
MarkerOutline: MarkerOutline.ToOption(),
352+
MarkerPatternShape: MarkerPatternShape.ToOption(),
353+
MultiMarkerPatternShape: MultiMarkerPatternShape.ToOption(),
354+
MarkerPattern: MarkerPattern.ToOption(),
355+
Marker: Marker.ToOption(),
356+
Base: Base.ToOption(),
357+
Width: Width.ToOption(),
358+
MultiWidth: MultiWidth.ToOption(),
359+
TextPosition: TextPosition.ToOption(),
360+
MultiTextPosition: MultiTextPosition.ToOption(),
361+
UseDefaults: UseDefaults.ToOptionV()
362+
);
363+
/// <summary>
364+
/// Creates a column chart, with bars plotted vertically
365+
///
366+
/// A column chart is a chart that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent.
367+
/// </summary>
368+
/// <param name="values">Sets the values that are plotted as the size of each bar.</param>
369+
/// <param name="Keys">Sets the keys associated with each bar.</param>
370+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
371+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
372+
/// <param name="Opacity">Sets the Opacity of the trace.</param>
373+
/// <param name="MultiOpacity">Sets the Opacity of each individual bar.</param>
374+
/// <param name="Text">Sets a text associated with each datum</param>
375+
/// <param name="MultiText">Sets individual text for each datum</param>
376+
/// <param name="MarkerColor">Sets the color of the bars</param>
377+
/// <param name="MarkerColorScale">Sets the colorscale for the bars. To have an effect, `MarkerColor` must map to color scale values.</param>
378+
/// <param name="MarkerOutline">Sets the color of the bar outlines</param>
379+
/// <param name="MarkerPatternShape">Sets a pattern shape for all bars</param>
380+
/// <param name="MultiMarkerPatternShape">Sets an individual pattern shape for each bar</param>
381+
/// <param name="MarkerPattern">Sets the marker pattern (use this for more finegrained control than the other pattern-associated arguments).</param>
382+
/// <param name="Marker">Sets the marker for the bars (use this for more finegrained control than the other marker-associated arguments).</param>
383+
/// <param name="Base">Sets where the bar base is drawn (in position axis units).</param>
384+
/// <param name="Width">Sets the bar width (in position axis units) of all bars.</param>
385+
/// <param name="MultiWidth">Sets the individual bar width (in position axis units) for each bar.</param>
386+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
387+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
388+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
389+
public static GenericChart.GenericChart Column<ValuesType, KeysType, TextType>(
390+
IEnumerable<ValuesType> values,
391+
IEnumerable<KeysType>? Keys = null,
392+
string? Name = null,
393+
bool? ShowLegend = null,
394+
double? Opacity = null,
395+
IEnumerable<double>? MultiOpacity = null,
396+
TextType? Text = null,
397+
IEnumerable<TextType>? MultiText = null,
398+
Color? MarkerColor = null,
399+
StyleParam.Colorscale? MarkerColorScale = null,
400+
Line? MarkerOutline = null,
401+
StyleParam.PatternShape? MarkerPatternShape = null,
402+
IEnumerable<StyleParam.PatternShape>? MultiMarkerPatternShape = null,
403+
Pattern? MarkerPattern = null,
404+
Marker? Marker = null,
405+
IConvertible? Base = null,
406+
IConvertible? Width = null,
407+
IEnumerable<IConvertible>? MultiWidth = null,
408+
StyleParam.TextPosition? TextPosition = null,
409+
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
410+
bool? UseDefaults = null
411+
)
412+
where ValuesType : IConvertible
413+
where KeysType : IConvertible
414+
where TextType : class, IConvertible
415+
=>
416+
Plotly.NET.Chart2D.Chart.Column<ValuesType, KeysType, TextType, IConvertible, IConvertible>(
417+
values: values,
418+
Keys: Keys.ToOption(),
419+
Name: Name.ToOption(),
420+
ShowLegend: ShowLegend.ToOptionV(),
421+
Opacity: Opacity.ToOptionV(),
422+
MultiOpacity: MultiOpacity.ToOption(),
423+
Text: Text.ToOption(),
424+
MultiText: MultiText.ToOption(),
425+
MarkerColor: MarkerColor.ToOption(),
426+
MarkerColorScale: MarkerColorScale.ToOption(),
427+
MarkerOutline: MarkerOutline.ToOption(),
428+
MarkerPatternShape: MarkerPatternShape.ToOption(),
429+
MultiMarkerPatternShape: MultiMarkerPatternShape.ToOption(),
430+
MarkerPattern: MarkerPattern.ToOption(),
431+
Marker: Marker.ToOption(),
432+
Base: Base.ToOption(),
433+
Width: Width.ToOption(),
434+
MultiWidth: MultiWidth.ToOption(),
435+
TextPosition: TextPosition.ToOption(),
436+
MultiTextPosition: MultiTextPosition.ToOption(),
437+
UseDefaults: UseDefaults.ToOptionV()
438+
);
287439
};
288440
}

Diff for: tests/Plotly.NET.Tests.CSharpConsole/Program.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ static void Main(string[] args)
1111
{
1212
Chart.Grid(
1313
nRows: 8,
14-
nCols: 3,
14+
nCols: 5,
1515
gCharts:
16-
new GenericChart []
16+
new GenericChart[]
1717
{
1818
Chart.Scatter<int,int,string>(
1919
x: new int [] { 1, 2 },
@@ -28,6 +28,14 @@ static void Main(string[] args)
2828
x: new int [] { 9, 10 },
2929
y: new int [] { 11, 12 }
3030
),
31+
Chart.Bar<int,string,string>(
32+
values: new int [] { 1,2 },
33+
Keys: new string [] { "first", "second"}
34+
),
35+
Chart.Column<int,string,string>(
36+
values: new int [] { 1,2 },
37+
Keys: new string [] { "first", "second"}
38+
),
3139
Chart.Scatter3D<int,int,int,string>(
3240
x: new int[] { 12, 13 },
3341
y: new int [] { 13, 14 },
@@ -36,27 +44,35 @@ static void Main(string[] args)
3644
),
3745
Chart.Invisible(),
3846
Chart.Invisible(),
47+
Chart.Invisible(),
48+
Chart.Invisible(),
3949
Chart.ScatterPolar<int,int,string>(
4050
theta: new int [] { 1, 2 },
4151
r: new int [] { 3, 4 },
4252
mode: Mode.Markers
4353
),
4454
Chart.Invisible(),
4555
Chart.Invisible(),
56+
Chart.Invisible(),
57+
Chart.Invisible(),
4658
Chart.ScatterGeo<int,int,string>(
4759
longitudes: new int [] { 1, 2 },
4860
latitudes: new int [] { 3, 4 },
4961
mode: Mode.Markers
5062
),
5163
Chart.Invisible(),
5264
Chart.Invisible(),
65+
Chart.Invisible(),
66+
Chart.Invisible(),
5367
Chart.ScatterTernary<int,int,int,IConvertible,string>(
5468
A: new int [] { 1, 2 },
5569
B: new int [] { 3, 4 },
5670
C: new int [] { 5, 6 }
5771
),
5872
Chart.Invisible(),
5973
Chart.Invisible(),
74+
Chart.Invisible(),
75+
Chart.Invisible(),
6076
Chart.Carpet<double,double,double,double,double,double>(
6177
carpetId: "testCarpet",
6278
A: new double [] {4.0, 4.0, 4.0, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0},
@@ -65,22 +81,28 @@ static void Main(string[] args)
6581
),
6682
Chart.Invisible(),
6783
Chart.Invisible(),
84+
Chart.Invisible(),
85+
Chart.Invisible(),
6886
Chart.Pie<double,string,string>(
6987
values: new double [] {1,2,3,4},
7088
Labels: new string [] {"soos", "saas", "fiif", "leel"}
7189
),
7290
Chart.Invisible(),
7391
Chart.Invisible(),
92+
Chart.Invisible(),
93+
Chart.Invisible(),
7494
Chart.ScatterSmith<double,double,string>(
7595
real: new double [] {1,2,3,4},
7696
imag: new double [] {1,2,3,4},
7797
mode: Mode.Markers
7898
),
7999
Chart.Invisible(),
80100
Chart.Invisible(),
101+
Chart.Invisible(),
102+
Chart.Invisible(),
81103
}
82104
)
83-
.WithSize(750,2000)
105+
.WithSize(1250,2000)
84106
.Show();
85107

86108
Chart.Point<int, int, string>(

0 commit comments

Comments
 (0)