Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ 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

### Fixed
- DateTimeAxis converting local time rather than UTC to TimeZone
- ErrorBarItem add marker

## [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 <[email protected]>
jorgectf
tangmanger <[email protected]>
168 changes: 167 additions & 1 deletion Source/Examples/ExampleLibrary/Series/ErrorBarSeriesExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Legends;
using OxyPlot.Series;
using System;

[Examples("ErrorBarSeries"), Tags("Series")]
public class ErrorBarSeriesExamples
Expand Down Expand Up @@ -72,5 +73,170 @@ public static PlotModel GetErrorBarSeriesThickErrorLines()

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; // -1 到 1
double y = Math.Sin(x * Math.PI * 3) * Math.Exp(-Math.Abs(x)) * 0.8;

// 添加一些随机脉冲效果
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;
}
}
}
41 changes: 41 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 Down
17 changes: 17 additions & 0 deletions Source/OxyPlot/Series/BarSeries/ErrorBarSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ protected override void RenderItem(
null,
LineJoin.Miter);
}
ErrorBarItem errorBarItem = item as ErrorBarItem;
if (errorBarItem != null)
{
if (errorBarItem.IsMarkerVisible)
{
ScreenPoint screenPoint = new ScreenPoint(upperErrorPoint.X + errorBarItem.MarkerOffset.X,
upperErrorPoint.Y + errorBarItem.MarkerOffset.Y);
rc.DrawMarker(screenPoint,
errorBarItem.MarkerType,
errorBarItem.CustomOutline,
errorBarItem.MarkerSize,
errorBarItem.MarkerColor,
errorBarItem.MarkerStrokeColor,
errorBarItem.MarkerStrokeThickness,
this.EdgeRenderingMode);
}
}
}
}
}
Loading