Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ All notable changes to this project will be documented in this file.
### Added

- Example to demonstrate how to create vertical BarSeries

- Example to demonstrate how to create ErrorBarSeries Marker
- Example to demonstrate how to create ErrorBarItem Spacing
-
### Fixed
- DateTimeAxis converting local time rather than UTC to TimeZone
- ErrorBarItem add marker
- ErrorBarItem add spacing

## [2.2.0] - 2024-09-03

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,4 @@ Dmytro Shaurin
Rustam Sayfutdinov
Konstantin Stukov <havendv@gmail.com>
jorgectf
tangmanger <tangmanger@163.com>
214 changes: 213 additions & 1 deletion Source/Examples/ExampleLibrary/Series/ErrorBarSeriesExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ExampleLibrary
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Legends;
using OxyPlot.Series;
using System;

[Examples("ErrorBarSeries"), Tags("Series")]
public class ErrorBarSeriesExamples
Expand All @@ -34,7 +36,7 @@ public static PlotModel GetErrorBarSeries()
model.Legends.Add(l);

var s1 = new ErrorBarSeries { Title = "Series 1", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1 };
s1.Items.Add(new ErrorBarItem { Value = 25, Error = 2 });
s1.Items.Add(new ErrorBarItem { Value = 35, Error = 2 });
s1.Items.Add(new ErrorBarItem { Value = 137, Error = 25 });
s1.Items.Add(new ErrorBarItem { Value = 18, Error = 4 });
s1.Items.Add(new ErrorBarItem { Value = 40, Error = 29 });
Expand Down Expand Up @@ -72,5 +74,215 @@ public static PlotModel GetErrorBarSeriesThickErrorLines()

return model;
}

[Example("ErrorBarItemSpacing")]
public static PlotModel GetErrorBarSpacingSeries()
{
var model = new PlotModel
{
Title = "ErrorBarItemSpacing"
};

var l = new Legend
{
LegendPlacement = LegendPlacement.Outside,
LegendPosition = LegendPosition.BottomCenter,
LegendOrientation = LegendOrientation.Horizontal,
LegendBorderThickness = 0
};

model.Legends.Add(l);

var s1 = new ErrorBarSeries { Title = "Series 1", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1 };
s1.Items.Add(new ErrorBarItem { Spacing = 10, Value = 35, Error = 2 });
s1.Items.Add(new ErrorBarItem { Spacing = 20, Value = 137, Error = 25 });
s1.Items.Add(new ErrorBarItem { Spacing = 30, Value = 18, Error = 4 });
s1.Items.Add(new ErrorBarItem { Spacing = 40, Value = 40, Error = 29 });

var s2 = new ErrorBarSeries { Title = "Series 2", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1 };
s2.Items.Add(new ErrorBarItem { Value = 35, Error = 20 });
s2.Items.Add(new ErrorBarItem { Value = 17, Error = 7 });
s2.Items.Add(new ErrorBarItem { Value = 118, Error = 44 });
s2.Items.Add(new ErrorBarItem { Value = 49, Error = 29 });

var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
categoryAxis.Labels.Add("Category A");
categoryAxis.Labels.Add("Category B");
categoryAxis.Labels.Add("Category C");
categoryAxis.Labels.Add("Category D");

var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0 };
model.Series.Add(s1);
model.Series.Add(s2);
model.Axes.Add(categoryAxis);
model.Axes.Add(valueAxis);

return model;
}
[Example("MarkerErrorBarSeries")]
[DocumentationExample("Series/MarkerErrorBarSeries")]
public static PlotModel GetMarkerErrorBarSeries()
{
var model = new PlotModel
{
Title = "MarkerErrorBarSeries"
};
var l = new Legend
{
LegendPlacement = LegendPlacement.Outside,
LegendPosition = LegendPosition.BottomCenter,
LegendOrientation = LegendOrientation.Horizontal,
LegendBorderThickness = 0
};

model.Legends.Add(l);

var s1 = new ErrorBarSeries { Title = "Series 1", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1 };
s1.Items.Add(new ErrorBarItem
{
Value = 25,
Error = 2,
IsMarkerVisible = true,
MarkerColor = OxyColors.Red,
MarkerType = MarkerType.Star,
MarkerSize = 5,
MarkerOffset = new ScreenPoint(5, 0),
MarkerStrokeColor = OxyColors.Blue,
MarkerStrokeThickness = 1,
});
s1.Items.Add(new ErrorBarItem
{
Value = 137,
Error = 25,
IsMarkerVisible = true,
MarkerColor = OxyColors.Yellow,
MarkerType = MarkerType.Cross,
MarkerSize = 5,
MarkerOffset = new ScreenPoint(0, 0),
MarkerStrokeColor = OxyColors.Red,
MarkerStrokeThickness = 1,
});
s1.Items.Add(new ErrorBarItem
{
Value = 18,
Error = 4,
IsMarkerVisible = true,
MarkerColor = OxyColors.Yellow,
MarkerType = MarkerType.Diamond,
MarkerSize = 8,
MarkerOffset = new ScreenPoint(0, 0),
MarkerStrokeColor = OxyColors.LightGreen,
MarkerStrokeThickness = 1,
});
s1.Items.Add(new ErrorBarItem
{
Value = 40,
Error = 29,
IsMarkerVisible = true,
MarkerColor = OxyColors.Yellow,
MarkerType = MarkerType.Custom,
CustomOutline = GetSpiralStar(),
MarkerSize = 30,
MarkerOffset = new ScreenPoint(50, 0),
MarkerStrokeColor = OxyColors.LightGreen,
MarkerStrokeThickness = 1,
});

var s2 = new ErrorBarSeries { Title = "Series 2", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1 };
s2.Items.Add(new ErrorBarItem
{
Value = 25,
Error = 2,
IsMarkerVisible = true,
MarkerColor = OxyColors.Red,
MarkerType = MarkerType.Square,
MarkerSize = 5,
MarkerOffset = new ScreenPoint(5, 0),
MarkerStrokeColor = OxyColors.Blue,
MarkerStrokeThickness = 1,
});
s2.Items.Add(new ErrorBarItem
{
Value = 137,
Error = 25,
IsMarkerVisible = true,
MarkerColor = OxyColors.Yellow,
MarkerType = MarkerType.Triangle,
MarkerSize = 5,
MarkerOffset = new ScreenPoint(0, 0),
MarkerStrokeColor = OxyColors.Red,
MarkerStrokeThickness = 1,
});
s2.Items.Add(new ErrorBarItem
{
Value = 18,
Error = 4,
IsMarkerVisible = true,
MarkerColor = OxyColors.Yellow,
MarkerType = MarkerType.Plus,
MarkerSize = 8,
MarkerOffset = new ScreenPoint(0, 0),
MarkerStrokeColor = OxyColors.LightGreen,
MarkerStrokeThickness = 1,
});
s2.Items.Add(new ErrorBarItem
{
Value = 40,
Error = 29,
IsMarkerVisible = true,
MarkerColor = OxyColors.GreenYellow,
MarkerType = MarkerType.Custom,
CustomOutline = GetHeartbeat(),
MarkerSize = 30,
MarkerOffset = new ScreenPoint(50, 0),
MarkerStrokeColor = OxyColors.BlueViolet,
MarkerStrokeThickness = 1,
});

var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
categoryAxis.Labels.Add("Category A");
categoryAxis.Labels.Add("Category B");
categoryAxis.Labels.Add("Category C");
categoryAxis.Labels.Add("Category D");

var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0 };
model.Series.Add(s1);
model.Series.Add(s2);
model.Axes.Add(categoryAxis);
model.Axes.Add(valueAxis);

return model;
}
public static ScreenPoint[] GetHeartbeat(int points = 20)
{
var outline = new ScreenPoint[points];
for (int i = 0; i < points; i++)
{
double x = 2.0 * i / (points - 1) - 1;
double y = Math.Sin(x * Math.PI * 3) * Math.Exp(-Math.Abs(x)) * 0.8;

// Add some random pulse effects
y += Math.Sin(x * Math.PI * 8) * 0.1 * Math.Exp(-x * x * 4);

outline[i] = new ScreenPoint(x, y);
}
return outline;
}
public static ScreenPoint[] GetSpiralStar(int points = 24, double tightness = 0.1)
{
var outline = new ScreenPoint[points];
for (int i = 0; i < points; i++)
{
double progress = (double)i / points;
double radius = 0.2 + 0.8 * progress;
double angle = 2 * Math.PI * (5 * progress + tightness * i);

outline[i] = new ScreenPoint(
Math.Cos(angle) * radius,
Math.Sin(angle) * radius
);
}
return outline;
}
}
}
46 changes: 46 additions & 0 deletions Source/OxyPlot/Series/BarSeries/ErrorBarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,47 @@ public ErrorBarItem(double value, double error, int categoryIndex = -1)
/// </summary>
public double Error { get; set; }

/// <summary>
/// Gets or sets the color of marker
/// </summary>
public OxyColor MarkerColor { get; set; }


/// <summary>
/// Gets or sets the marker Type
/// </summary>
public MarkerType MarkerType { get; set; }

/// <summary>
/// Gets or sets a custom polygon outline for the point marker.
/// </summary>
public ScreenPoint[] CustomOutline { get; set; }

/// <summary>
/// Gets or sets the marker size
/// </summary>
public int MarkerSize { get; set; }

/// <summary>
/// Gets or sets the marker visible
/// </summary>
public bool IsMarkerVisible { get; set; }

/// <summary>
/// Gets or sets the marker offset
/// </summary>
public ScreenPoint MarkerOffset { get; set; }

/// <summary>
/// Gets or sets the marker stroke color
/// </summary>
public OxyColor MarkerStrokeColor { get; set; }

/// <summary>
/// Gets or sets the marker stroke thickness
/// </summary>
public double MarkerStrokeThickness { get; set; }

/// <summary>
/// Returns c# code that generates this instance.
/// </summary>
Expand All @@ -61,5 +102,10 @@ public override string ToCode()

return CodeGenerator.FormatConstructor(this.GetType(), "{0},{1}", this.Value, this.Error);
}
/// <summary>
/// Bar spacing: the gap between adjacent bars
/// </summary>
public double Spacing { get; set; }

}
}
Loading