Skip to content

Commit 1baea3b

Browse files
authored
Overlapping bar series (#1265) (#1627)
1 parent 0be0190 commit 1baea3b

6 files changed

Lines changed: 44 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ All notable changes to this project will be documented in this file.
3434
- Examples of full plot area polar plots with non-zero minimums (#1586)
3535
- Read-Only collection interfaces for .NET 4.0 (#1600)
3636
- Add PlotModel.AssignColorsToInvisibleSeries property to control whether invisible series are included or skipped when assigning automatic colors (#1599)
37+
- Overlapping bar series (#1265)
3738

3839
### Changed
3940
- Legends model (#644)

Source/Examples/ExampleLibrary/Series/BarSeriesExamples.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,29 @@ public static PlotModel BaseValueStacked()
909909
return model;
910910
}
911911

912+
[Example("BaseValue (overlaping)")]
913+
public static PlotModel BaseValueOverlaping()
914+
{
915+
var model = new PlotModel { Title = "BaseValue (overlaping)", Subtitle = "BaseValue = -1" };
916+
var series1 = new BarSeries { Title = "Series 1", IsStacked = true, OverlapsStack = true, BaseValue = -1 };
917+
series1.Items.Add(new BarItem { Value = 1 });
918+
series1.Items.Add(new BarItem { Value = 2 });
919+
model.Series.Add(series1);
920+
var series2 = new BarSeries { Title = "Series 2", IsStacked = true, OverlapsStack = true, BaseValue = -1, BarWidth = 0.5 };
921+
series2.Items.Add(new BarItem { Value = 4 });
922+
series2.Items.Add(new BarItem { Value = 7 });
923+
model.Series.Add(series2);
924+
925+
var categoryAxis = new CategoryAxis
926+
{
927+
Title = "Category",
928+
Position = AxisPosition.Left
929+
};
930+
categoryAxis.Labels.AddRange(new[] { "A", "B" });
931+
model.Axes.Add(categoryAxis);
932+
return model;
933+
}
934+
912935
[Example("GapWidth 0%")]
913936
public static PlotModel GapWidth0()
914937
{
@@ -1015,12 +1038,18 @@ public static PlotModel AllInOne()
10151038
s6.Items.Add(new BarItem { Value = 68 });
10161039
s6.Items.Add(new BarItem { Value = 12 });
10171040

1041+
var s7 = new BarSeries { Title = "Series 7", IsStacked = true, OverlapsStack = true, StrokeColor = OxyColors.Black, StrokeThickness = 1, LabelFormatString = "{0:0}", LabelPlacement = LabelPlacement.Base, StackGroup = "3", BarWidth = 0.5 };
1042+
s7.Items.Add(new BarItem { Value = 10 });
1043+
s7.Items.Add(new BarItem { Value = 80 });
1044+
s7.Items.Add(new BarItem { Value = 100, CategoryIndex = categoryD });
1045+
10181046
model.Series.Add(s1);
10191047
model.Series.Add(s2);
10201048
model.Series.Add(s3);
10211049
model.Series.Add(s4);
10221050
model.Series.Add(s5);
10231051
model.Series.Add(s6);
1052+
model.Series.Add(s7);
10241053
model.Axes.Add(categoryAxis);
10251054
model.Axes.Add(valueAxis);
10261055
return model;

Source/OxyPlot/Series/BarSeries/BarSeries.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public BarSeries()
6767
/// <inheritdoc/>
6868
public bool IsStacked { get; set; }
6969

70+
/// <inheritdoc/>
71+
public bool OverlapsStack { get; set; }
72+
7073
/// <summary>
7174
/// Gets or sets the label format string.
7275
/// </summary>
@@ -198,7 +201,7 @@ protected internal override void UpdateMaxMin()
198201
this.Manager.SetCurrentMinValue(stackIndex, i, minTemp);
199202

200203
var stackedMaxValue = this.Manager.GetCurrentMaxValue(stackIndex, i);
201-
if (!double.IsNaN(stackedMaxValue))
204+
if (!this.OverlapsStack && !double.IsNaN(stackedMaxValue))
202205
{
203206
maxTemp += stackedMaxValue;
204207
}
@@ -380,7 +383,7 @@ public override void Render(IRenderContext rc)
380383

381384
// Get base- and topValue
382385
var baseValue = double.NaN;
383-
if (this.IsStacked)
386+
if (this.IsStacked && !this.OverlapsStack)
384387
{
385388
baseValue = this.Manager.GetCurrentBaseValue(stackIndex, categoryIndex, value < 0);
386389
}

Source/OxyPlot/Series/BarSeries/ErrorBarSeries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected internal override void UpdateMaxMin()
8282
this.Manager.SetCurrentMinValue(stackIndex, i, minTemp);
8383

8484
var stackedMaxValue = this.Manager.GetCurrentMaxValue(stackIndex, i);
85-
if (!double.IsNaN(stackedMaxValue))
85+
if (!this.OverlapsStack && !double.IsNaN(stackedMaxValue))
8686
{
8787
maxTemp += stackedMaxValue;
8888
}

Source/OxyPlot/Series/BarSeries/IStackableSeries.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public interface IStackableSeries : IBarSeries
1919
/// </summary>
2020
bool IsStacked { get; }
2121

22+
/// <summary>
23+
/// Gets a value indicating whether this series should overlap its stack when <see cref="IsStacked"/> is true.
24+
/// </summary>
25+
bool OverlapsStack { get; }
26+
2227
/// <summary>
2328
/// Gets the stack group.
2429
/// </summary>

Source/OxyPlot/Series/BarSeries/IntervalBarSeries.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public IntervalBarSeries()
6767
/// <inheritdoc/>
6868
public bool IsStacked => true;
6969

70+
/// <inheritdoc/>
71+
public bool OverlapsStack => true;
72+
7073
/// <summary>
7174
/// Gets or sets the label color.
7275
/// </summary>

0 commit comments

Comments
 (0)