454
Source/Examples/ExampleLibrary/Series/AreaSeriesExamples.cs
Normal file
454
Source/Examples/ExampleLibrary/Series/AreaSeriesExamples.cs
Normal file
@@ -0,0 +1,454 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="AreaSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("AreaSeries"), Tags("Series")]
|
||||
public static class AreaSeriesExamples
|
||||
{
|
||||
[Example("Default style")]
|
||||
[DocumentationExample("Series/AreaSeries")]
|
||||
public static PlotModel DefaultStyle()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with default style" };
|
||||
plotModel1.Series.Add(CreateExampleAreaSeries());
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("Different stroke colors")]
|
||||
public static PlotModel DifferentColors()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with different stroke colors" };
|
||||
var areaSeries1 = CreateExampleAreaSeries();
|
||||
areaSeries1.Color = OxyColors.Red;
|
||||
areaSeries1.Color2 = OxyColors.Blue;
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("Crossing lines")]
|
||||
public static PlotModel CrossingLines()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with crossing lines" };
|
||||
var areaSeries1 = new AreaSeries();
|
||||
areaSeries1.Points.Add(new DataPoint(0, 50));
|
||||
areaSeries1.Points.Add(new DataPoint(10, 140));
|
||||
areaSeries1.Points.Add(new DataPoint(20, 60));
|
||||
areaSeries1.Points2.Add(new DataPoint(0, 60));
|
||||
areaSeries1.Points2.Add(new DataPoint(5, 80));
|
||||
areaSeries1.Points2.Add(new DataPoint(20, 70));
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("Custom TrackerFormatString")]
|
||||
public static PlotModel TrackerFormatString()
|
||||
{
|
||||
var model = new PlotModel { Title = "AreaSeries with custom TrackerFormatString" };
|
||||
|
||||
// the axis titles will be used in the default tracker format string
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "X-axis" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Y-axis" });
|
||||
|
||||
var areaSeries1 = CreateExampleAreaSeries();
|
||||
areaSeries1.Title = "X={2:0.0} Y={4:0.0}";
|
||||
areaSeries1.TrackerFormatString = "X={2:0.0} Y={4:0.0}";
|
||||
model.Series.Add(areaSeries1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Constant baseline (empty Points2)")]
|
||||
public static PlotModel ConstantBaseline()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with constant baseline", Subtitle = "Empty Points2, ConstantY2 = 0 (default)" };
|
||||
var areaSeries1 = new AreaSeries();
|
||||
areaSeries1.Points.Add(new DataPoint(0, 50));
|
||||
areaSeries1.Points.Add(new DataPoint(10, 140));
|
||||
areaSeries1.Points.Add(new DataPoint(20, 60));
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("Constant baseline (empty Points2, ConstantY2=NaN)")]
|
||||
public static PlotModel ConstantBaselineNaN()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with constant baseline", Subtitle = "Empty Points2, ConstantY2 = NaN" };
|
||||
var areaSeries1 = new AreaSeries();
|
||||
areaSeries1.Points.Add(new DataPoint(0, 50));
|
||||
areaSeries1.Points.Add(new DataPoint(10, 140));
|
||||
areaSeries1.Points.Add(new DataPoint(20, 60));
|
||||
areaSeries1.ConstantY2 = double.NaN;
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("Constant baseline (ItemsSource and DataField2 not set)")]
|
||||
public static PlotModel ConstantBaselineItemsSource()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "AreaSeries with constant baseline", Subtitle = "ItemsSource and DataField2 not set, ConstantY2 = -20" };
|
||||
var areaSeries1 = new AreaSeries();
|
||||
var points = new[] { new DataPoint(0, 50), new DataPoint(10, 140), new DataPoint(20, 60) };
|
||||
areaSeries1.ItemsSource = points;
|
||||
areaSeries1.DataFieldX = "X";
|
||||
areaSeries1.DataFieldY = "Y";
|
||||
areaSeries1.ConstantY2 = -20;
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
[Example("LineSeries and AreaSeries")]
|
||||
public static PlotModel LineSeriesAndAreaSeries()
|
||||
{
|
||||
var plotModel1 = new PlotModel { Title = "LineSeries and AreaSeries" };
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Bottom };
|
||||
plotModel1.Axes.Add(linearAxis1);
|
||||
var linearAxis2 = new LinearAxis();
|
||||
plotModel1.Axes.Add(linearAxis2);
|
||||
var areaSeries1 = new AreaSeries
|
||||
{
|
||||
Fill = OxyColors.LightBlue,
|
||||
DataFieldX2 = "Time",
|
||||
DataFieldY2 = "Minimum",
|
||||
Color = OxyColors.Red,
|
||||
StrokeThickness = 0,
|
||||
MarkerFill = OxyColors.Transparent,
|
||||
DataFieldX = "Time",
|
||||
DataFieldY = "Maximum"
|
||||
};
|
||||
areaSeries1.Points2.Add(new DataPoint(0, -5.04135905692417));
|
||||
areaSeries1.Points2.Add(new DataPoint(2.5, -4.91731850813018));
|
||||
areaSeries1.Points2.Add(new DataPoint(5, -4.45266314658926));
|
||||
areaSeries1.Points2.Add(new DataPoint(7.5, -3.87303874542613));
|
||||
areaSeries1.Points2.Add(new DataPoint(10, -3.00101110255393));
|
||||
areaSeries1.Points2.Add(new DataPoint(12.5, -2.17980725503518));
|
||||
areaSeries1.Points2.Add(new DataPoint(15, -1.67332229254456));
|
||||
areaSeries1.Points2.Add(new DataPoint(17.5, -1.10537158549082));
|
||||
areaSeries1.Points2.Add(new DataPoint(20, -0.6145459544447));
|
||||
areaSeries1.Points2.Add(new DataPoint(22.5, 0.120028106039404));
|
||||
areaSeries1.Points2.Add(new DataPoint(25, 1.06357270435597));
|
||||
areaSeries1.Points2.Add(new DataPoint(27.5, 1.87301405606466));
|
||||
areaSeries1.Points2.Add(new DataPoint(30, 2.57569854952195));
|
||||
areaSeries1.Points2.Add(new DataPoint(32.5, 3.59165537664278));
|
||||
areaSeries1.Points2.Add(new DataPoint(35, 4.87991958133872));
|
||||
areaSeries1.Points2.Add(new DataPoint(37.5, 6.36214537958714));
|
||||
areaSeries1.Points2.Add(new DataPoint(40, 7.62564585126268));
|
||||
areaSeries1.Points2.Add(new DataPoint(42.5, 8.69606320261772));
|
||||
areaSeries1.Points2.Add(new DataPoint(45, 10.0118704438265));
|
||||
areaSeries1.Points2.Add(new DataPoint(47.5, 11.0434480519236));
|
||||
areaSeries1.Points2.Add(new DataPoint(50, 11.9794171576758));
|
||||
areaSeries1.Points2.Add(new DataPoint(52.5, 12.9591851832621));
|
||||
areaSeries1.Points2.Add(new DataPoint(55, 14.172107889304));
|
||||
areaSeries1.Points2.Add(new DataPoint(57.5, 15.5520057698488));
|
||||
areaSeries1.Points2.Add(new DataPoint(60, 17.2274942386092));
|
||||
areaSeries1.Points2.Add(new DataPoint(62.5, 18.6983982186757));
|
||||
areaSeries1.Points2.Add(new DataPoint(65, 20.4560332001448));
|
||||
areaSeries1.Points2.Add(new DataPoint(67.5, 22.4867327382261));
|
||||
areaSeries1.Points2.Add(new DataPoint(70, 24.5319674302041));
|
||||
areaSeries1.Points2.Add(new DataPoint(72.5, 26.600547815813));
|
||||
areaSeries1.Points2.Add(new DataPoint(75, 28.5210891459701));
|
||||
areaSeries1.Points2.Add(new DataPoint(77.5, 30.6793080755413));
|
||||
areaSeries1.Points2.Add(new DataPoint(80, 33.0546651200646));
|
||||
areaSeries1.Points2.Add(new DataPoint(82.5, 35.3256065179713));
|
||||
areaSeries1.Points2.Add(new DataPoint(85, 37.6336074839968));
|
||||
areaSeries1.Points2.Add(new DataPoint(87.5, 40.2012266359763));
|
||||
areaSeries1.Points2.Add(new DataPoint(90, 42.8923555399256));
|
||||
areaSeries1.Points2.Add(new DataPoint(92.5, 45.8665211907432));
|
||||
areaSeries1.Points2.Add(new DataPoint(95, 48.8200195945427));
|
||||
areaSeries1.Points2.Add(new DataPoint(97.5, 51.8304284402311));
|
||||
areaSeries1.Points2.Add(new DataPoint(100, 54.6969868542147));
|
||||
areaSeries1.Points2.Add(new DataPoint(102.5, 57.7047292990632));
|
||||
areaSeries1.Points2.Add(new DataPoint(105, 60.4216644602929));
|
||||
areaSeries1.Points2.Add(new DataPoint(107.5, 62.926258762519));
|
||||
areaSeries1.Points2.Add(new DataPoint(110, 65.1829734629407));
|
||||
areaSeries1.Points2.Add(new DataPoint(112.5, 67.2365592083133));
|
||||
areaSeries1.Points2.Add(new DataPoint(115, 69.5713628691022));
|
||||
areaSeries1.Points2.Add(new DataPoint(117.5, 71.7267046705944));
|
||||
areaSeries1.Points2.Add(new DataPoint(120, 73.633463102781));
|
||||
areaSeries1.Points2.Add(new DataPoint(122.5, 75.4660150158061));
|
||||
areaSeries1.Points2.Add(new DataPoint(125, 77.5669292504745));
|
||||
areaSeries1.Points2.Add(new DataPoint(127.5, 79.564218544664));
|
||||
areaSeries1.Points2.Add(new DataPoint(130, 81.8631309028078));
|
||||
areaSeries1.Points2.Add(new DataPoint(132.5, 83.9698189969034));
|
||||
areaSeries1.Points2.Add(new DataPoint(135, 86.3847886532009));
|
||||
areaSeries1.Points2.Add(new DataPoint(137.5, 88.5559348267764));
|
||||
areaSeries1.Points2.Add(new DataPoint(140, 91.0455050418365));
|
||||
areaSeries1.Points2.Add(new DataPoint(142.5, 93.6964157585504));
|
||||
areaSeries1.Points2.Add(new DataPoint(145, 96.284336864941));
|
||||
areaSeries1.Points2.Add(new DataPoint(147.5, 98.7508602689723));
|
||||
areaSeries1.Points2.Add(new DataPoint(150, 100.904510594255));
|
||||
areaSeries1.Points2.Add(new DataPoint(152.5, 103.266136681506));
|
||||
areaSeries1.Points2.Add(new DataPoint(155, 105.780951269521));
|
||||
areaSeries1.Points2.Add(new DataPoint(157.5, 108.032859257065));
|
||||
areaSeries1.Points2.Add(new DataPoint(160, 110.035478448093));
|
||||
areaSeries1.Points2.Add(new DataPoint(162.5, 112.10655731615));
|
||||
areaSeries1.Points2.Add(new DataPoint(165, 114.37480786097));
|
||||
areaSeries1.Points2.Add(new DataPoint(167.5, 116.403992550869));
|
||||
areaSeries1.Points2.Add(new DataPoint(170, 118.61663988727));
|
||||
areaSeries1.Points2.Add(new DataPoint(172.5, 120.538730287384));
|
||||
areaSeries1.Points2.Add(new DataPoint(175, 122.515721057177));
|
||||
areaSeries1.Points2.Add(new DataPoint(177.5, 124.474386629124));
|
||||
areaSeries1.Points2.Add(new DataPoint(180, 126.448283293214));
|
||||
areaSeries1.Points2.Add(new DataPoint(182.5, 128.373811322299));
|
||||
areaSeries1.Points2.Add(new DataPoint(185, 130.33627914667));
|
||||
areaSeries1.Points2.Add(new DataPoint(187.5, 132.487933658477));
|
||||
areaSeries1.Points2.Add(new DataPoint(190, 134.716989778456));
|
||||
areaSeries1.Points2.Add(new DataPoint(192.5, 136.817287595392));
|
||||
areaSeries1.Points2.Add(new DataPoint(195, 139.216488664698));
|
||||
areaSeries1.Points2.Add(new DataPoint(197.5, 141.50803227574));
|
||||
areaSeries1.Points2.Add(new DataPoint(200, 143.539586683614));
|
||||
areaSeries1.Points2.Add(new DataPoint(202.5, 145.535911545221));
|
||||
areaSeries1.Points2.Add(new DataPoint(205, 147.516964978686));
|
||||
areaSeries1.Points2.Add(new DataPoint(207.5, 149.592416731684));
|
||||
areaSeries1.Points2.Add(new DataPoint(210, 151.600983566512));
|
||||
areaSeries1.Points2.Add(new DataPoint(212.5, 153.498210993362));
|
||||
areaSeries1.Points2.Add(new DataPoint(215, 155.512606828247));
|
||||
areaSeries1.Points2.Add(new DataPoint(217.5, 157.426564302774));
|
||||
areaSeries1.Points2.Add(new DataPoint(220, 159.364474964172));
|
||||
areaSeries1.Points2.Add(new DataPoint(222.5, 161.152806492128));
|
||||
areaSeries1.Points2.Add(new DataPoint(225, 162.679069434562));
|
||||
areaSeries1.Points2.Add(new DataPoint(227.5, 163.893622036741));
|
||||
areaSeries1.Points2.Add(new DataPoint(230, 165.475827621238));
|
||||
areaSeries1.Points2.Add(new DataPoint(232.5, 167.303960444734));
|
||||
areaSeries1.Points2.Add(new DataPoint(235, 169.259393394952));
|
||||
areaSeries1.Points2.Add(new DataPoint(237.5, 171.265193646758));
|
||||
areaSeries1.Points2.Add(new DataPoint(240, 173.074304345192));
|
||||
areaSeries1.Points2.Add(new DataPoint(242.5, 174.975492766814));
|
||||
areaSeries1.Points2.Add(new DataPoint(245, 176.684088218484));
|
||||
areaSeries1.Points2.Add(new DataPoint(247.5, 178.406887247603));
|
||||
areaSeries1.Points.Add(new DataPoint(0, 5.0184649433561));
|
||||
areaSeries1.Points.Add(new DataPoint(2.5, 5.27685959268215));
|
||||
areaSeries1.Points.Add(new DataPoint(5, 5.81437064628786));
|
||||
areaSeries1.Points.Add(new DataPoint(7.5, 6.51022475040994));
|
||||
areaSeries1.Points.Add(new DataPoint(10, 7.49921246878766));
|
||||
areaSeries1.Points.Add(new DataPoint(12.5, 8.41941631823751));
|
||||
areaSeries1.Points.Add(new DataPoint(15, 9.09826907222079));
|
||||
areaSeries1.Points.Add(new DataPoint(17.5, 9.89500750098145));
|
||||
areaSeries1.Points.Add(new DataPoint(20, 10.6633345249404));
|
||||
areaSeries1.Points.Add(new DataPoint(22.5, 11.6249613445368));
|
||||
areaSeries1.Points.Add(new DataPoint(25, 12.8816391467497));
|
||||
areaSeries1.Points.Add(new DataPoint(27.5, 13.9665185705603));
|
||||
areaSeries1.Points.Add(new DataPoint(30, 14.8501816818724));
|
||||
areaSeries1.Points.Add(new DataPoint(32.5, 16.0683128022441));
|
||||
areaSeries1.Points.Add(new DataPoint(35, 17.5378799723172));
|
||||
areaSeries1.Points.Add(new DataPoint(37.5, 19.1262752954039));
|
||||
areaSeries1.Points.Add(new DataPoint(40, 20.4103953650735));
|
||||
areaSeries1.Points.Add(new DataPoint(42.5, 21.5430627723891));
|
||||
areaSeries1.Points.Add(new DataPoint(45, 22.9105459463366));
|
||||
areaSeries1.Points.Add(new DataPoint(47.5, 23.9802361888719));
|
||||
areaSeries1.Points.Add(new DataPoint(50, 24.8659461235003));
|
||||
areaSeries1.Points.Add(new DataPoint(52.5, 25.7303194442439));
|
||||
areaSeries1.Points.Add(new DataPoint(55, 26.7688545912359));
|
||||
areaSeries1.Points.Add(new DataPoint(57.5, 28.0545112571933));
|
||||
areaSeries1.Points.Add(new DataPoint(60, 29.7036634266394));
|
||||
areaSeries1.Points.Add(new DataPoint(62.5, 31.2273634344467));
|
||||
areaSeries1.Points.Add(new DataPoint(65, 33.1038196356519));
|
||||
areaSeries1.Points.Add(new DataPoint(67.5, 35.2639893610328));
|
||||
areaSeries1.Points.Add(new DataPoint(70, 37.434293559489));
|
||||
areaSeries1.Points.Add(new DataPoint(72.5, 39.7109359368267));
|
||||
areaSeries1.Points.Add(new DataPoint(75, 41.7573881676222));
|
||||
areaSeries1.Points.Add(new DataPoint(77.5, 44.0460374479862));
|
||||
areaSeries1.Points.Add(new DataPoint(80, 46.5098714746581));
|
||||
areaSeries1.Points.Add(new DataPoint(82.5, 48.7754012129155));
|
||||
areaSeries1.Points.Add(new DataPoint(85, 51.1619816926597));
|
||||
areaSeries1.Points.Add(new DataPoint(87.5, 53.9036778414639));
|
||||
areaSeries1.Points.Add(new DataPoint(90, 56.7448825012636));
|
||||
areaSeries1.Points.Add(new DataPoint(92.5, 59.9294987878434));
|
||||
areaSeries1.Points.Add(new DataPoint(95, 63.0148831289797));
|
||||
areaSeries1.Points.Add(new DataPoint(97.5, 66.0721745989622));
|
||||
areaSeries1.Points.Add(new DataPoint(100, 68.8980036274521));
|
||||
areaSeries1.Points.Add(new DataPoint(102.5, 71.7719322611447));
|
||||
areaSeries1.Points.Add(new DataPoint(105, 74.4206055336728));
|
||||
areaSeries1.Points.Add(new DataPoint(107.5, 76.816198386632));
|
||||
areaSeries1.Points.Add(new DataPoint(110, 79.0040432726983));
|
||||
areaSeries1.Points.Add(new DataPoint(112.5, 80.9617606926066));
|
||||
areaSeries1.Points.Add(new DataPoint(115, 83.1345574620341));
|
||||
areaSeries1.Points.Add(new DataPoint(117.5, 85.0701022046479));
|
||||
areaSeries1.Points.Add(new DataPoint(120, 86.8557530286516));
|
||||
areaSeries1.Points.Add(new DataPoint(122.5, 88.5673387745243));
|
||||
areaSeries1.Points.Add(new DataPoint(125, 90.6003321543338));
|
||||
areaSeries1.Points.Add(new DataPoint(127.5, 92.439864576254));
|
||||
areaSeries1.Points.Add(new DataPoint(130, 94.5383744861178));
|
||||
areaSeries1.Points.Add(new DataPoint(132.5, 96.4600166864507));
|
||||
areaSeries1.Points.Add(new DataPoint(135, 98.6091052949006));
|
||||
areaSeries1.Points.Add(new DataPoint(137.5, 100.496459351478));
|
||||
areaSeries1.Points.Add(new DataPoint(140, 102.705767030085));
|
||||
areaSeries1.Points.Add(new DataPoint(142.5, 105.009994476992));
|
||||
areaSeries1.Points.Add(new DataPoint(145, 107.31287026052));
|
||||
areaSeries1.Points.Add(new DataPoint(147.5, 109.584842542272));
|
||||
areaSeries1.Points.Add(new DataPoint(150, 111.641435600837));
|
||||
areaSeries1.Points.Add(new DataPoint(152.5, 113.988459973544));
|
||||
areaSeries1.Points.Add(new DataPoint(155, 116.50349048027));
|
||||
areaSeries1.Points.Add(new DataPoint(157.5, 118.753612704274));
|
||||
areaSeries1.Points.Add(new DataPoint(160, 120.801728924085));
|
||||
areaSeries1.Points.Add(new DataPoint(162.5, 122.902486914165));
|
||||
areaSeries1.Points.Add(new DataPoint(165, 125.104391935796));
|
||||
areaSeries1.Points.Add(new DataPoint(167.5, 127.06056966547));
|
||||
areaSeries1.Points.Add(new DataPoint(170, 129.217086578495));
|
||||
areaSeries1.Points.Add(new DataPoint(172.5, 131.151968896274));
|
||||
areaSeries1.Points.Add(new DataPoint(175, 133.159906275133));
|
||||
areaSeries1.Points.Add(new DataPoint(177.5, 135.065263957561));
|
||||
areaSeries1.Points.Add(new DataPoint(180, 137.041870026822));
|
||||
areaSeries1.Points.Add(new DataPoint(182.5, 138.937477489811));
|
||||
areaSeries1.Points.Add(new DataPoint(185, 140.776914926282));
|
||||
areaSeries1.Points.Add(new DataPoint(187.5, 142.786975776398));
|
||||
areaSeries1.Points.Add(new DataPoint(190, 144.862762377347));
|
||||
areaSeries1.Points.Add(new DataPoint(192.5, 146.89654967049));
|
||||
areaSeries1.Points.Add(new DataPoint(195, 149.204343821204));
|
||||
areaSeries1.Points.Add(new DataPoint(197.5, 151.369748673527));
|
||||
areaSeries1.Points.Add(new DataPoint(200, 153.324438580137));
|
||||
areaSeries1.Points.Add(new DataPoint(202.5, 155.173148715344));
|
||||
areaSeries1.Points.Add(new DataPoint(205, 157.0501827528));
|
||||
areaSeries1.Points.Add(new DataPoint(207.5, 159.109122278359));
|
||||
areaSeries1.Points.Add(new DataPoint(210, 161.044446932778));
|
||||
areaSeries1.Points.Add(new DataPoint(212.5, 162.942364031841));
|
||||
areaSeries1.Points.Add(new DataPoint(215, 164.966769883021));
|
||||
areaSeries1.Points.Add(new DataPoint(217.5, 166.89711806788));
|
||||
areaSeries1.Points.Add(new DataPoint(220, 168.906874949069));
|
||||
areaSeries1.Points.Add(new DataPoint(222.5, 170.85692034995));
|
||||
areaSeries1.Points.Add(new DataPoint(225, 172.602125010408));
|
||||
areaSeries1.Points.Add(new DataPoint(227.5, 173.964258466598));
|
||||
areaSeries1.Points.Add(new DataPoint(230, 175.629908385654));
|
||||
areaSeries1.Points.Add(new DataPoint(232.5, 177.495778359378));
|
||||
areaSeries1.Points.Add(new DataPoint(235, 179.432933300749));
|
||||
areaSeries1.Points.Add(new DataPoint(237.5, 181.400180771342));
|
||||
areaSeries1.Points.Add(new DataPoint(240, 183.232300309899));
|
||||
areaSeries1.Points.Add(new DataPoint(242.5, 185.225502661441));
|
||||
areaSeries1.Points.Add(new DataPoint(245, 186.979590140413));
|
||||
areaSeries1.Points.Add(new DataPoint(247.5, 188.816640077725));
|
||||
areaSeries1.Title = "Maximum/Minimum";
|
||||
plotModel1.Series.Add(areaSeries1);
|
||||
|
||||
var lineSeries1 = new LineSeries
|
||||
{
|
||||
Color = OxyColors.Blue,
|
||||
MarkerFill = OxyColors.Transparent,
|
||||
DataFieldX = "Time",
|
||||
DataFieldY = "Value"
|
||||
};
|
||||
lineSeries1.Points.Add(new DataPoint(0, -0.011447056784037));
|
||||
lineSeries1.Points.Add(new DataPoint(2.5, 0.179770542275985));
|
||||
lineSeries1.Points.Add(new DataPoint(5, 0.6808537498493));
|
||||
lineSeries1.Points.Add(new DataPoint(7.5, 1.31859300249191));
|
||||
lineSeries1.Points.Add(new DataPoint(10, 2.24910068311687));
|
||||
lineSeries1.Points.Add(new DataPoint(12.5, 3.11980453160117));
|
||||
lineSeries1.Points.Add(new DataPoint(15, 3.71247338983811));
|
||||
lineSeries1.Points.Add(new DataPoint(17.5, 4.39481795774531));
|
||||
lineSeries1.Points.Add(new DataPoint(20, 5.02439428524784));
|
||||
lineSeries1.Points.Add(new DataPoint(22.5, 5.87249472528812));
|
||||
lineSeries1.Points.Add(new DataPoint(25, 6.97260592555283));
|
||||
lineSeries1.Points.Add(new DataPoint(27.5, 7.91976631331247));
|
||||
lineSeries1.Points.Add(new DataPoint(30, 8.71294011569719));
|
||||
lineSeries1.Points.Add(new DataPoint(32.5, 9.82998408944345));
|
||||
lineSeries1.Points.Add(new DataPoint(35, 11.208899776828));
|
||||
lineSeries1.Points.Add(new DataPoint(37.5, 12.7442103374955));
|
||||
lineSeries1.Points.Add(new DataPoint(40, 14.0180206081681));
|
||||
lineSeries1.Points.Add(new DataPoint(42.5, 15.1195629875034));
|
||||
lineSeries1.Points.Add(new DataPoint(45, 16.4612081950815));
|
||||
lineSeries1.Points.Add(new DataPoint(47.5, 17.5118421203978));
|
||||
lineSeries1.Points.Add(new DataPoint(50, 18.4226816405881));
|
||||
lineSeries1.Points.Add(new DataPoint(52.5, 19.344752313753));
|
||||
lineSeries1.Points.Add(new DataPoint(55, 20.47048124027));
|
||||
lineSeries1.Points.Add(new DataPoint(57.5, 21.8032585135211));
|
||||
lineSeries1.Points.Add(new DataPoint(60, 23.4655788326243));
|
||||
lineSeries1.Points.Add(new DataPoint(62.5, 24.9628808265612));
|
||||
lineSeries1.Points.Add(new DataPoint(65, 26.7799264178984));
|
||||
lineSeries1.Points.Add(new DataPoint(67.5, 28.8753610496295));
|
||||
lineSeries1.Points.Add(new DataPoint(70, 30.9831304948466));
|
||||
lineSeries1.Points.Add(new DataPoint(72.5, 33.1557418763199));
|
||||
lineSeries1.Points.Add(new DataPoint(75, 35.1392386567962));
|
||||
lineSeries1.Points.Add(new DataPoint(77.5, 37.3626727617638));
|
||||
lineSeries1.Points.Add(new DataPoint(80, 39.7822682973613));
|
||||
lineSeries1.Points.Add(new DataPoint(82.5, 42.0505038654434));
|
||||
lineSeries1.Points.Add(new DataPoint(85, 44.3977945883283));
|
||||
lineSeries1.Points.Add(new DataPoint(87.5, 47.0524522387201));
|
||||
lineSeries1.Points.Add(new DataPoint(90, 49.8186190205946));
|
||||
lineSeries1.Points.Add(new DataPoint(92.5, 52.8980099892933));
|
||||
lineSeries1.Points.Add(new DataPoint(95, 55.9174513617612));
|
||||
lineSeries1.Points.Add(new DataPoint(97.5, 58.9513015195966));
|
||||
lineSeries1.Points.Add(new DataPoint(100, 61.7974952408334));
|
||||
lineSeries1.Points.Add(new DataPoint(102.5, 64.738330780104));
|
||||
lineSeries1.Points.Add(new DataPoint(105, 67.4211349969828));
|
||||
lineSeries1.Points.Add(new DataPoint(107.5, 69.8712285745755));
|
||||
lineSeries1.Points.Add(new DataPoint(110, 72.0935083678195));
|
||||
lineSeries1.Points.Add(new DataPoint(112.5, 74.0991599504599));
|
||||
lineSeries1.Points.Add(new DataPoint(115, 76.3529601655682));
|
||||
lineSeries1.Points.Add(new DataPoint(117.5, 78.3984034376212));
|
||||
lineSeries1.Points.Add(new DataPoint(120, 80.2446080657163));
|
||||
lineSeries1.Points.Add(new DataPoint(122.5, 82.0166768951652));
|
||||
lineSeries1.Points.Add(new DataPoint(125, 84.0836307024042));
|
||||
lineSeries1.Points.Add(new DataPoint(127.5, 86.002041560459));
|
||||
lineSeries1.Points.Add(new DataPoint(130, 88.2007526944628));
|
||||
lineSeries1.Points.Add(new DataPoint(132.5, 90.2149178416771));
|
||||
lineSeries1.Points.Add(new DataPoint(135, 92.4969469740507));
|
||||
lineSeries1.Points.Add(new DataPoint(137.5, 94.5261970891274));
|
||||
lineSeries1.Points.Add(new DataPoint(140, 96.875636035961));
|
||||
lineSeries1.Points.Add(new DataPoint(142.5, 99.3532051177711));
|
||||
lineSeries1.Points.Add(new DataPoint(145, 101.798603562731));
|
||||
lineSeries1.Points.Add(new DataPoint(147.5, 104.167851405622));
|
||||
lineSeries1.Points.Add(new DataPoint(150, 106.272973097546));
|
||||
lineSeries1.Points.Add(new DataPoint(152.5, 108.627298327525));
|
||||
lineSeries1.Points.Add(new DataPoint(155, 111.142220874895));
|
||||
lineSeries1.Points.Add(new DataPoint(157.5, 113.39323598067));
|
||||
lineSeries1.Points.Add(new DataPoint(160, 115.418603686089));
|
||||
lineSeries1.Points.Add(new DataPoint(162.5, 117.504522115157));
|
||||
lineSeries1.Points.Add(new DataPoint(165, 119.739599898383));
|
||||
lineSeries1.Points.Add(new DataPoint(167.5, 121.732281108169));
|
||||
lineSeries1.Points.Add(new DataPoint(170, 123.916863232882));
|
||||
lineSeries1.Points.Add(new DataPoint(172.5, 125.845349591829));
|
||||
lineSeries1.Points.Add(new DataPoint(175, 127.837813666155));
|
||||
lineSeries1.Points.Add(new DataPoint(177.5, 129.769825293343));
|
||||
lineSeries1.Points.Add(new DataPoint(180, 131.745076660018));
|
||||
lineSeries1.Points.Add(new DataPoint(182.5, 133.655644406055));
|
||||
lineSeries1.Points.Add(new DataPoint(185, 135.556597036476));
|
||||
lineSeries1.Points.Add(new DataPoint(187.5, 137.637454717438));
|
||||
lineSeries1.Points.Add(new DataPoint(190, 139.789876077902));
|
||||
lineSeries1.Points.Add(new DataPoint(192.5, 141.856918632941));
|
||||
lineSeries1.Points.Add(new DataPoint(195, 144.210416242951));
|
||||
lineSeries1.Points.Add(new DataPoint(197.5, 146.438890474634));
|
||||
lineSeries1.Points.Add(new DataPoint(200, 148.432012631876));
|
||||
lineSeries1.Points.Add(new DataPoint(202.5, 150.354530130282));
|
||||
lineSeries1.Points.Add(new DataPoint(205, 152.283573865743));
|
||||
lineSeries1.Points.Add(new DataPoint(207.5, 154.350769505022));
|
||||
lineSeries1.Points.Add(new DataPoint(210, 156.322715249645));
|
||||
lineSeries1.Points.Add(new DataPoint(212.5, 158.220287512602));
|
||||
lineSeries1.Points.Add(new DataPoint(215, 160.239688355634));
|
||||
lineSeries1.Points.Add(new DataPoint(217.5, 162.161841185327));
|
||||
lineSeries1.Points.Add(new DataPoint(220, 164.135674956621));
|
||||
lineSeries1.Points.Add(new DataPoint(222.5, 166.004863421039));
|
||||
lineSeries1.Points.Add(new DataPoint(225, 167.640597222485));
|
||||
lineSeries1.Points.Add(new DataPoint(227.5, 168.928940251669));
|
||||
lineSeries1.Points.Add(new DataPoint(230, 170.552868003446));
|
||||
lineSeries1.Points.Add(new DataPoint(232.5, 172.399869402056));
|
||||
lineSeries1.Points.Add(new DataPoint(235, 174.346163347851));
|
||||
lineSeries1.Points.Add(new DataPoint(237.5, 176.33268720905));
|
||||
lineSeries1.Points.Add(new DataPoint(240, 178.153302327545));
|
||||
lineSeries1.Points.Add(new DataPoint(242.5, 180.100497714128));
|
||||
lineSeries1.Points.Add(new DataPoint(245, 181.831839179449));
|
||||
lineSeries1.Points.Add(new DataPoint(247.5, 183.611763662664));
|
||||
lineSeries1.Title = "Average";
|
||||
plotModel1.Series.Add(lineSeries1);
|
||||
return plotModel1;
|
||||
}
|
||||
|
||||
private static AreaSeries CreateExampleAreaSeries()
|
||||
{
|
||||
var areaSeries1 = new AreaSeries();
|
||||
areaSeries1.Points.Add(new DataPoint(0, 50));
|
||||
areaSeries1.Points.Add(new DataPoint(10, 40));
|
||||
areaSeries1.Points.Add(new DataPoint(20, 60));
|
||||
areaSeries1.Points2.Add(new DataPoint(0, 60));
|
||||
areaSeries1.Points2.Add(new DataPoint(5, 80));
|
||||
areaSeries1.Points2.Add(new DataPoint(20, 70));
|
||||
return areaSeries1;
|
||||
}
|
||||
}
|
||||
}
|
||||
1176
Source/Examples/ExampleLibrary/Series/BarSeriesExamples.cs
Normal file
1176
Source/Examples/ExampleLibrary/Series/BarSeriesExamples.cs
Normal file
File diff suppressed because it is too large
Load Diff
201
Source/Examples/ExampleLibrary/Series/BoxPlotSeriesExamples.cs
Normal file
201
Source/Examples/ExampleLibrary/Series/BoxPlotSeriesExamples.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="BoxPlotSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Gets the median.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Annotations;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("BoxPlotSeries"), Tags("Series")]
|
||||
public class BoxPlotSeriesExamples
|
||||
{
|
||||
[Example("BoxPlot")]
|
||||
public static PlotModel BoxPlot()
|
||||
{
|
||||
const int boxes = 10;
|
||||
|
||||
var model = new PlotModel { Title = string.Format("BoxPlot (n={0})", boxes) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new BoxPlotSeries
|
||||
{
|
||||
Title = "BoxPlotSeries",
|
||||
BoxWidth = 0.3
|
||||
};
|
||||
|
||||
var random = new Random(31);
|
||||
for (var i = 0; i < boxes; i++)
|
||||
{
|
||||
double x = i;
|
||||
var points = 5 + random.Next(15);
|
||||
var values = new List<double>();
|
||||
for (var j = 0; j < points; j++)
|
||||
{
|
||||
values.Add(random.Next(0, 20));
|
||||
}
|
||||
|
||||
values.Sort();
|
||||
var median = GetMedian(values);
|
||||
var mean = values.Average();
|
||||
int r = values.Count % 2;
|
||||
double firstQuartil = GetMedian(values.Take((values.Count + r) / 2));
|
||||
double thirdQuartil = GetMedian(values.Skip((values.Count - r) / 2));
|
||||
|
||||
var iqr = thirdQuartil - firstQuartil;
|
||||
var step = iqr * 1.5;
|
||||
var upperWhisker = thirdQuartil + step;
|
||||
upperWhisker = values.Where(v => v <= upperWhisker).Max();
|
||||
var lowerWhisker = firstQuartil - step;
|
||||
lowerWhisker = values.Where(v => v >= lowerWhisker).Min();
|
||||
|
||||
var outliers = new[] { upperWhisker + random.Next(1, 10), lowerWhisker - random.Next(1, 10) };
|
||||
|
||||
s1.Items.Add(new BoxPlotItem(x, lowerWhisker, firstQuartil, median, thirdQuartil, upperWhisker) { Mean = mean, Outliers = outliers });
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1 });
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the median.
|
||||
/// </summary>
|
||||
/// <param name="values">The values.</param>
|
||||
/// <returns></returns>
|
||||
private static double GetMedian(IEnumerable<double> values)
|
||||
{
|
||||
var sortedInterval = new List<double>(values);
|
||||
sortedInterval.Sort();
|
||||
var count = sortedInterval.Count;
|
||||
if (count % 2 == 1)
|
||||
{
|
||||
return sortedInterval[(count - 1) / 2];
|
||||
}
|
||||
|
||||
return 0.5 * sortedInterval[count / 2] + 0.5 * sortedInterval[(count / 2) - 1];
|
||||
}
|
||||
|
||||
[Example("BoxPlot (minimal data/ink ratio)")]
|
||||
public static PlotModel BoxPlot2()
|
||||
{
|
||||
var model = BoxPlot();
|
||||
var boxPlotSeries = (BoxPlotSeries)model.Series[0];
|
||||
boxPlotSeries.ShowMedianAsDot = true;
|
||||
boxPlotSeries.OutlierType = MarkerType.Cross;
|
||||
boxPlotSeries.Fill = OxyColors.Black;
|
||||
boxPlotSeries.ShowBox = false;
|
||||
boxPlotSeries.WhiskerWidth = 0;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("BoxPlot (dashed line)")]
|
||||
public static PlotModel BoxPlot3()
|
||||
{
|
||||
var model = BoxPlot();
|
||||
var boxPlotSeries = (BoxPlotSeries)model.Series[0];
|
||||
boxPlotSeries.LineStyle = LineStyle.Dash;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Outlier type = Cross")]
|
||||
public static PlotModel OutlierTypeCross()
|
||||
{
|
||||
var model = BoxPlot();
|
||||
var boxPlotSeries = (BoxPlotSeries)model.Series[0];
|
||||
boxPlotSeries.OutlierType = MarkerType.Cross;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Outlier type = Custom")]
|
||||
public static PlotModel OutlierTypeCustom()
|
||||
{
|
||||
var model = BoxPlot();
|
||||
var boxPlotSeries = (BoxPlotSeries)model.Series[0];
|
||||
boxPlotSeries.OutlierType = MarkerType.Custom;
|
||||
boxPlotSeries.OutlierOutline = new[] { new ScreenPoint(-1, -1), new ScreenPoint(1, 1), new ScreenPoint(-1, 1), new ScreenPoint(1, -1) };
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Michelson-Morley experiment")]
|
||||
public static PlotModel MichelsonMorleyExperiment()
|
||||
{
|
||||
//// http://www.gutenberg.org/files/11753/11753-h/11753-h.htm
|
||||
//// http://en.wikipedia.org/wiki/Michelson%E2%80%93Morley_experiment
|
||||
//// http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/morley.html
|
||||
|
||||
var model = new PlotModel();
|
||||
|
||||
var boxPlotSeries = new BoxPlotSeries
|
||||
{
|
||||
Title = "Results",
|
||||
Stroke = OxyColors.Black,
|
||||
StrokeThickness = 1,
|
||||
OutlierSize = 2,
|
||||
BoxWidth = 0.4
|
||||
};
|
||||
|
||||
// note: approximated data values (not the original values)
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(0, 740, 850, 945, 980, 1070) { Outliers = new[] { 650.0 }});
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(1, 750, 805, 845, 890, 970) { Outliers = new double[] { }});
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(2, 845, 847, 855, 880, 910) { Outliers = new[] { 640.0, 950, 970 }});
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(3, 720, 760, 820, 870, 910) { Outliers = new double[] { }});
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(4, 730, 805, 807, 870, 950) { Outliers = new double[] { }});
|
||||
model.Series.Add(boxPlotSeries);
|
||||
model.Annotations.Add(new LineAnnotation { Type = LineAnnotationType.Horizontal, LineStyle = LineStyle.Solid, Y = 792.458, Text = "true speed" });
|
||||
var categoryAxis = new CategoryAxis
|
||||
{
|
||||
Title = "Experiment No.",
|
||||
};
|
||||
categoryAxis.Labels.AddRange(new[] { "1", "2", "3", "4", "5" });
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Speed of light (km/s minus 299,000)", MajorStep = 100, MinorStep = 100 });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("BoxPlot (DateTime axis)")]
|
||||
[DocumentationExample("Series/BoxPlotSeries")]
|
||||
public static PlotModel BoxPlotSeries_DateTimeAxis()
|
||||
{
|
||||
var m = new PlotModel();
|
||||
var x0 = DateTimeAxis.ToDouble(new DateTime(2013, 05, 04));
|
||||
m.Axes.Add(new DateTimeAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = x0 - 0.9,
|
||||
Maximum = x0 + 1.9,
|
||||
IntervalType = DateTimeIntervalType.Days,
|
||||
MajorStep = 1,
|
||||
MinorStep = 1,
|
||||
StringFormat = "yyyy-MM-dd"
|
||||
});
|
||||
var boxPlotSeries = new BoxPlotSeries
|
||||
{
|
||||
TrackerFormatString = "X: {1:yyyy-MM-dd}\nUpper Whisker: {2:0.00}\nThird Quartil: {3:0.00}\nMedian: {4:0.00}\nFirst Quartil: {5:0.00}\nLower Whisker: {6:0.00}\nMean: {7:0.00}"
|
||||
};
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(x0, 10, 14, 16, 20, 22) { Mean = 17, Outliers = new[] { 23.5 }});
|
||||
boxPlotSeries.Items.Add(new BoxPlotItem(x0 + 1, 11, 13, 14, 15, 18) { Outliers = new[] { 23.4 }});
|
||||
m.Series.Add(boxPlotSeries);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
216
Source/Examples/ExampleLibrary/Series/ContourSeriesExamples.cs
Normal file
216
Source/Examples/ExampleLibrary/Series/ContourSeriesExamples.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ContourSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("ContourSeries"), Tags("Series")]
|
||||
public class ContourSeriesExamples
|
||||
{
|
||||
private static Func<double, double, double> peaks = (x, y) =>
|
||||
3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1))
|
||||
- 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y)
|
||||
- 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
|
||||
|
||||
private static Func<double, double, double> openContours = (x, y) =>
|
||||
(x * x) / (y * y + 1)
|
||||
+ (y * y) / (x * x + 1);
|
||||
|
||||
[Example("Peaks")]
|
||||
public static PlotModel Peaks()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05)
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks LabelStep = 1, ContourLevelStep = PI/2")]
|
||||
public static PlotModel PeaksLabelStep1LevelStepPI2()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks LabelStep = 1, ContourLevelStep = PI/2" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
ContourLevelStep = Math.PI / 2,
|
||||
LabelStep = 1
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks LabelStep = 2, ContourLevelStep = 0.5")]
|
||||
public static PlotModel PeaksLabelStep2()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks LabelStep = 2, ContourLevelStep = 0.5" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
ContourLevelStep = 0.5,
|
||||
LabelStep = 2
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks LabelStep = 2, ContourLevelStep = 0.33")]
|
||||
public static PlotModel PeaksLabelStep2LevelStep033()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks LabelStep = 2, ContourLevelStep = 0.33" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
ContourLevelStep = 0.33,
|
||||
LabelStep = 2
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks LabelStep = 3, ContourLevelStep = 1")]
|
||||
public static PlotModel PeaksLabelStep3()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks LabelStep = 3, ContourLevelStep = 1" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
LabelStep = 3
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks MultiLabel")]
|
||||
public static PlotModel PeaksMultiLabel()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks MultiLabel" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
MultiLabel = true
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks LabelSpacing = 400")]
|
||||
public static PlotModel PeaksLabelSpacing400()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks LabelSpacing = 400" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
MultiLabel = true,
|
||||
LabelSpacing = 400
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks (different contour colors)")]
|
||||
[DocumentationExample("Series/ContourSeries")]
|
||||
public static PlotModel PeaksWithColors()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks" };
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.05),
|
||||
ContourColors = new[] { OxyColors.SeaGreen, OxyColors.RoyalBlue, OxyColors.IndianRed }
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Peaks (wide array)")]
|
||||
public static PlotModel WideArrayPeaks()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -3.16262, Maximum = 3.162 });
|
||||
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-1, 1, 0.05)
|
||||
};
|
||||
cs.Data = ArrayBuilder.Evaluate(peaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Subtitle = cs.Data.GetLength(0) + "×" + cs.Data.GetLength(1);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Open Contours")]
|
||||
public static PlotModel OpenContours()
|
||||
{
|
||||
var model = new PlotModel();
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05),
|
||||
RowCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.05)
|
||||
};
|
||||
|
||||
cs.Data = ArrayBuilder.Evaluate(openContours, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Series.Add(cs);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Logarithmic Peaks")]
|
||||
public static PlotModel LogPeaks()
|
||||
{
|
||||
Func<double, double, double> logPeaks = (x, y) => peaks(Math.Log(x) / 10, Math.Log(y) / 10);
|
||||
|
||||
var model = new PlotModel();
|
||||
var coordinates = ArrayBuilder.CreateVector(-3, 3, 0.05);
|
||||
for (var i = 0; i < coordinates.Length; i++)
|
||||
{
|
||||
coordinates[i] = Math.Exp(coordinates[i] * 10);
|
||||
}
|
||||
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
ColumnCoordinates = coordinates,
|
||||
RowCoordinates = coordinates
|
||||
};
|
||||
|
||||
cs.Data = ArrayBuilder.Evaluate(logPeaks, cs.ColumnCoordinates, cs.RowCoordinates);
|
||||
model.Series.Add(cs);
|
||||
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Left });
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ErrorBarSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("ErrorBarSeries"), Tags("Series")]
|
||||
public class ErrorBarSeriesExamples
|
||||
{
|
||||
[Example("ErrorBarSeries")]
|
||||
[DocumentationExample("Series/ErrorBarSeries")]
|
||||
public static PlotModel GetErrorBarSeries()
|
||||
{
|
||||
var model = new PlotModel
|
||||
{
|
||||
Title = "ErrorBarSeries"
|
||||
};
|
||||
|
||||
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 });
|
||||
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 });
|
||||
|
||||
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("ErrorBarSeries (thick error lines)")]
|
||||
public static PlotModel GetErrorBarSeriesThickErrorLines()
|
||||
{
|
||||
var model = GetErrorBarSeries();
|
||||
foreach (ErrorBarSeries s in model.Series)
|
||||
{
|
||||
s.ErrorWidth = 0;
|
||||
s.ErrorStrokeThickness = 4;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ExtrapolationLineSeries.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the ExtrapolationLineSeries.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary.Series
|
||||
{
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Legends;
|
||||
using OxyPlot.Series;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="ExtrapolatedLineSeries" />.
|
||||
/// </summary>
|
||||
[Examples("ExtrapolationLineSeries")]
|
||||
[Tags("Series")]
|
||||
public static class ExtrapolationLineSeriesExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an example showing a line fit which is extrapolated
|
||||
/// beyond the range given by the data points.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Line Fit (Ignore Extrapolation For Scaling)")]
|
||||
public static PlotModel ExtrapolatedLineSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "Line Fit" };
|
||||
|
||||
var scatterSeries = new ScatterSeries()
|
||||
{
|
||||
Title = "Data",
|
||||
};
|
||||
|
||||
scatterSeries.Points.Add(new ScatterPoint(3, 1.4));
|
||||
scatterSeries.Points.Add(new ScatterPoint(4, 1.3));
|
||||
scatterSeries.Points.Add(new ScatterPoint(5, 1.6));
|
||||
scatterSeries.Points.Add(new ScatterPoint(6, 2.3));
|
||||
scatterSeries.Points.Add(new ScatterPoint(7, 2.2));
|
||||
scatterSeries.Points.Add(new ScatterPoint(8, 2.5));
|
||||
scatterSeries.Points.Add(new ScatterPoint(9, 2.9));
|
||||
scatterSeries.Points.Add(new ScatterPoint(10, 3.1));
|
||||
scatterSeries.Points.Add(new ScatterPoint(11, 3.1));
|
||||
scatterSeries.Points.Add(new ScatterPoint(12, 3.8));
|
||||
|
||||
model.Series.Add(scatterSeries);
|
||||
|
||||
CalculateLinearRegressionParameters(scatterSeries.Points, out double slope, out double intercept);
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = "Fit",
|
||||
Color = OxyColors.Black,
|
||||
LineStyle = LineStyle.Solid,
|
||||
ExtrapolationColor = OxyColors.DarkGray,
|
||||
ExtrapolationLineStyle = LineStyle.Dash,
|
||||
StrokeThickness = 3,
|
||||
IgnoreExtraplotationForScaling = true,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(double.NegativeInfinity, scatterSeries.Points.Select(p => p.X).Min()));
|
||||
lineSeries.Intervals.Add(new DataRange(scatterSeries.Points.Select(p => p.X).Max(), double.PositiveInfinity));
|
||||
|
||||
var fitPoints = Enumerable
|
||||
.Range(-100, 200)
|
||||
.Select(x => new DataPoint(x, (slope * x) + intercept));
|
||||
|
||||
lineSeries.Points.AddRange(fitPoints);
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.BottomRight,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing a third-order polynomial with extra- and interpolation style.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Interpolation")]
|
||||
public static PlotModel InterpolationStyleLineSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "Interpolation" };
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = "Third Order Polynomial",
|
||||
Color = OxyColors.Black,
|
||||
LineStyle = LineStyle.Dash,
|
||||
ExtrapolationColor = OxyColors.Gray,
|
||||
ExtrapolationLineStyle = LineStyle.Dot,
|
||||
StrokeThickness = 3,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(double.NegativeInfinity, -15));
|
||||
lineSeries.Intervals.Add(new DataRange(10, 30));
|
||||
lineSeries.Intervals.Add(new DataRange(55, double.PositiveInfinity));
|
||||
|
||||
var coefficients = new double[] { 0.1, -6.0, -12, 0 };
|
||||
|
||||
double PolynomialValue(double x, IEnumerable<double> coeff)
|
||||
{
|
||||
// Horner's schema
|
||||
return coeff.Aggregate((acc, coefficient) => (acc * x) + coefficient);
|
||||
}
|
||||
|
||||
var points = Enumerable
|
||||
.Range(-30, 100)
|
||||
.Select(x => new DataPoint(x, PolynomialValue(x, coefficients)));
|
||||
|
||||
lineSeries.Points.AddRange(points);
|
||||
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.TopCenter,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing a third-order polynomial with extra- and
|
||||
/// interpolation style and an inverted y-axis.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Interpolation (Y Axis reversed)")]
|
||||
public static PlotModel TwoColorLineSeriesReversed()
|
||||
{
|
||||
return InterpolationStyleLineSeries().ReverseYAxis();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example where the provided extrapolation
|
||||
/// intervals overlap with each other.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Intersecting Intervals")]
|
||||
public static PlotModel IntersectingIntervals()
|
||||
{
|
||||
var model = new PlotModel { Title = "Intersecting Intervals" };
|
||||
|
||||
var i1 = new DataRange(-20, 20);
|
||||
var i2 = new DataRange(0, 30);
|
||||
var i3 = new DataRange(10, 40);
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = $"Overlapping intervals {i1}, {i2}, {i3}",
|
||||
Color = OxyColors.Black,
|
||||
LineStyle = LineStyle.Solid,
|
||||
ExtrapolationColor = OxyColors.Gray,
|
||||
ExtrapolationLineStyle = LineStyle.Dot,
|
||||
StrokeThickness = 3,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(i1);
|
||||
lineSeries.Intervals.Add(i2);
|
||||
lineSeries.Intervals.Add(i3);
|
||||
|
||||
var coefficients = new double[] { 0.1, -6.0, -12, 0 };
|
||||
|
||||
double PolynomialValue(double x, IEnumerable<double> coeff)
|
||||
{
|
||||
// Horner's schema
|
||||
return coeff.Aggregate((acc, coefficient) => (acc * x) + coefficient);
|
||||
}
|
||||
|
||||
var points = Enumerable
|
||||
.Range(-30, 100)
|
||||
.Select(x => new DataPoint(x, PolynomialValue(x, coefficients)));
|
||||
|
||||
lineSeries.Points.AddRange(points);
|
||||
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.TopCenter,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing a line using custom dash arrays for the
|
||||
/// normal and extrapolated parts of the curve.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Custom Dashes")]
|
||||
public static PlotModel CustomDashes()
|
||||
{
|
||||
var model = new PlotModel { Title = "Custom Dashes" };
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = "y = 5",
|
||||
Color = OxyColors.Black,
|
||||
LineStyle = LineStyle.Dash,
|
||||
Dashes = new double[] { 5, 1 },
|
||||
ExtrapolationColor = OxyColors.Gray,
|
||||
ExtrapolationLineStyle = LineStyle.Dot,
|
||||
ExtrapolationDashes = new double[] { 1, 5 },
|
||||
StrokeThickness = 3,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(double.NegativeInfinity, 0));
|
||||
|
||||
var points = Enumerable
|
||||
.Range(-100, 200)
|
||||
.Select(x => new DataPoint(x, 5));
|
||||
|
||||
lineSeries.Points.AddRange(points);
|
||||
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.TopCenter,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example to test the performance with 100000 points and 100 intervals.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Many Intervals")]
|
||||
public static PlotModel ManyIntervals()
|
||||
{
|
||||
var model = new PlotModel { Title = "ManyIntervals" };
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = "y = x",
|
||||
Color = OxyColors.Red,
|
||||
LineStyle = LineStyle.Solid,
|
||||
ExtrapolationLineStyle = LineStyle.Solid,
|
||||
StrokeThickness = 3,
|
||||
IgnoreExtraplotationForScaling = true,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(-1000, 10_000));
|
||||
|
||||
var intervals = Enumerable
|
||||
.Range(0, 98)
|
||||
.Select(x => new DataRange(1000 * x, (1000 * x) + 500));
|
||||
|
||||
foreach(var interval in intervals)
|
||||
lineSeries.Intervals.Add(interval);
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(200_000, double.PositiveInfinity));
|
||||
|
||||
var points = Enumerable
|
||||
.Range(0, 100_000)
|
||||
.Select(x => new DataPoint(x, x));
|
||||
|
||||
lineSeries.Points.AddRange(points);
|
||||
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.TopCenter,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example where Moore's law is fitted and
|
||||
/// extrapolated to the future.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Moore's Law")]
|
||||
public static PlotModel MooresLaw()
|
||||
{
|
||||
var model = new PlotModel { Title = "Moore's Law" };
|
||||
|
||||
var scatterSeries = new ScatterSeries()
|
||||
{
|
||||
Title = "Data",
|
||||
};
|
||||
|
||||
scatterSeries.Points.AddRange(GetPointForMooresLaw());
|
||||
|
||||
model.Series.Add(scatterSeries);
|
||||
|
||||
model.Axes.Add(new LinearAxis { Title = "Year", Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LogarithmicAxis { Title = "Transistors (in thousands)", Position = AxisPosition.Left });
|
||||
|
||||
CalculateLinearRegressionParameters(scatterSeries.Points.Select(p => new ScatterPoint(p.X, Math.Log10(p.Y))), out double slope, out double intercept);
|
||||
|
||||
var lineSeries = new ExtrapolationLineSeries
|
||||
{
|
||||
Title = "Fit and Extrapolation",
|
||||
Color = OxyColors.Black,
|
||||
LineStyle = LineStyle.Solid,
|
||||
ExtrapolationColor = OxyColors.Blue,
|
||||
ExtrapolationLineStyle = LineStyle.Dot,
|
||||
StrokeThickness = 3,
|
||||
};
|
||||
|
||||
lineSeries.Intervals.Add(new DataRange(2015, double.PositiveInfinity));
|
||||
|
||||
var fitPoints = Enumerable
|
||||
.Range(1970, 55)
|
||||
.Select(x => new DataPoint(x, Math.Pow(10, (slope * x) + intercept)));
|
||||
|
||||
lineSeries.Points.AddRange(fitPoints);
|
||||
|
||||
model.Series.Add(lineSeries);
|
||||
|
||||
var legend = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.TopCenter,
|
||||
};
|
||||
|
||||
model.Legends.Add(legend);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the slope and intercept of a linear regression line through the provided points.
|
||||
/// </summary>
|
||||
private static void CalculateLinearRegressionParameters(IEnumerable<ScatterPoint> points, out double slope, out double intercept)
|
||||
{
|
||||
if (points == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(points));
|
||||
}
|
||||
|
||||
if (points.Count() < 2)
|
||||
{
|
||||
throw new ArgumentException("at least two points required", nameof(points));
|
||||
}
|
||||
|
||||
var meanX = points.Select(p => p.X).Average();
|
||||
var meanY = points.Select(p => p.Y).Average();
|
||||
|
||||
var cov = Covariance(points, meanX, meanY);
|
||||
var var2_x = Variance2(points.Select(p => p.X));
|
||||
|
||||
slope = cov / var2_x;
|
||||
intercept = meanY - (slope * meanX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the covariance between the points x and y values.
|
||||
/// </summary>
|
||||
private static double Covariance(IEnumerable<ScatterPoint> points, double meanX, double meanY)
|
||||
{
|
||||
var res = points.Sum(p => p.X * p.Y);
|
||||
|
||||
res -= points.Count() * meanX * meanY;
|
||||
res /= points.Count() - 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the squared variance of a quantity.
|
||||
/// </summary>
|
||||
private static double Variance2(IEnumerable<double> values)
|
||||
{
|
||||
var mean = values.Average();
|
||||
|
||||
var res = values.Sum(x => x * x);
|
||||
|
||||
res -= values.Count() * mean * mean;
|
||||
res /= values.Count() - 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns data points to demonstrate Moore's law.
|
||||
/// Source: https://www.karlrupp.net/2015/06/40-years-of-microprocessor-trend-data/.
|
||||
/// </summary>
|
||||
private static IEnumerable<ScatterPoint> GetPointForMooresLaw()
|
||||
{
|
||||
yield return new ScatterPoint(1971.875, 2.30824152676);
|
||||
yield return new ScatterPoint(1972.30769231, 3.55452235561);
|
||||
yield return new ScatterPoint(1974.32692308, 6.09756235221);
|
||||
yield return new ScatterPoint(1979.56730769, 29.1637757405);
|
||||
yield return new ScatterPoint(1982.30769231, 135.772714211);
|
||||
yield return new ScatterPoint(1985.91346154, 273.841963426);
|
||||
yield return new ScatterPoint(1986.25, 109.411381058);
|
||||
yield return new ScatterPoint(1988.65384615, 121.881418484);
|
||||
yield return new ScatterPoint(1989.47115385, 1207.90074743);
|
||||
yield return new ScatterPoint(1990.57692308, 1207.90074743);
|
||||
yield return new ScatterPoint(1992.40384615, 1207.90074743);
|
||||
yield return new ScatterPoint(1992.69230769, 3105.90022362);
|
||||
yield return new ScatterPoint(1992.69230769, 1113.97385999);
|
||||
yield return new ScatterPoint(1993.02884615, 1715.43789634);
|
||||
yield return new ScatterPoint(1993.41346154, 3105.90022362);
|
||||
yield return new ScatterPoint(1993.41346154, 922.239565104);
|
||||
yield return new ScatterPoint(1994.71153846, 1910.95297497);
|
||||
yield return new ScatterPoint(1994.71153846, 2788.12666541);
|
||||
yield return new ScatterPoint(1995.43269231, 9646.61619911);
|
||||
yield return new ScatterPoint(1995.72115385, 3105.90022362);
|
||||
yield return new ScatterPoint(1996.15384615, 5473.70326288);
|
||||
yield return new ScatterPoint(1996.34615385, 6792.52507006);
|
||||
yield return new ScatterPoint(1996.34615385, 3651.74127255);
|
||||
yield return new ScatterPoint(1996.44230769, 4293.51021008);
|
||||
yield return new ScatterPoint(1996.82692308, 9646.61619911);
|
||||
yield return new ScatterPoint(1997.35576923, 5473.70326288);
|
||||
yield return new ScatterPoint(1997.45192308, 3554.52235561);
|
||||
yield return new ScatterPoint(1997.54807692, 8896.4911282);
|
||||
yield return new ScatterPoint(1997.64423077, 7566.6953714);
|
||||
yield return new ScatterPoint(1998.89423077, 15261.3780258);
|
||||
yield return new ScatterPoint(1999.13461538, 9389.79801048);
|
||||
yield return new ScatterPoint(1999.18269231, 6978.3058486);
|
||||
yield return new ScatterPoint(1999.47115385, 9389.79801048);
|
||||
yield return new ScatterPoint(1999.47115385, 21673.9216957);
|
||||
yield return new ScatterPoint(2000.19230769, 22266.7201035);
|
||||
yield return new ScatterPoint(2000.67307692, 28387.3596476);
|
||||
yield return new ScatterPoint(2000.67307692, 37180.2666391);
|
||||
yield return new ScatterPoint(2001.10576923, 29163.7757405);
|
||||
yield return new ScatterPoint(2001.20192308, 42550.6550247);
|
||||
yield return new ScatterPoint(2001.68269231, 25482.9674798);
|
||||
yield return new ScatterPoint(2001.82692308, 37180.2666391);
|
||||
yield return new ScatterPoint(2002.40384615, 55730.6040127);
|
||||
yield return new ScatterPoint(2002.78846154, 38197.1754928);
|
||||
yield return new ScatterPoint(2002.88461538, 220673.406908);
|
||||
yield return new ScatterPoint(2003.41346154, 151247.254531);
|
||||
yield return new ScatterPoint(2003.50961538, 54246.9093701);
|
||||
yield return new ScatterPoint(2003.65384615, 106498.563535);
|
||||
yield return new ScatterPoint(2004.80769231, 125214.968907);
|
||||
yield return new ScatterPoint(2004.80769231, 106498.563535);
|
||||
yield return new ScatterPoint(2004.80769231, 273841.963426);
|
||||
yield return new ScatterPoint(2005.72115385, 232909.659246);
|
||||
yield return new ScatterPoint(2005.81730769, 112403.866377);
|
||||
yield return new ScatterPoint(2005.96153846, 305052.789027);
|
||||
yield return new ScatterPoint(2006.05769231, 115478.198469);
|
||||
yield return new ScatterPoint(2006.875, 378551.524926);
|
||||
yield return new ScatterPoint(2006.875, 155383.983127);
|
||||
yield return new ScatterPoint(2006.92307692, 245824.406892);
|
||||
yield return new ScatterPoint(2006.97115385, 296931.48482);
|
||||
yield return new ScatterPoint(2006.97115385, 582941.534714);
|
||||
yield return new ScatterPoint(2007.06730769, 151247.254531);
|
||||
yield return new ScatterPoint(2007.64423077, 582941.534714);
|
||||
yield return new ScatterPoint(2007.74038462, 232909.659246);
|
||||
yield return new ScatterPoint(2007.78846154, 805842.187761);
|
||||
yield return new ScatterPoint(2007.83653846, 115478.198469);
|
||||
yield return new ScatterPoint(2007.98076923, 509367.521678);
|
||||
yield return new ScatterPoint(2008.22115385, 445079.406236);
|
||||
yield return new ScatterPoint(2008.46153846, 410469.838044);
|
||||
yield return new ScatterPoint(2009.18269231, 457252.669897);
|
||||
yield return new ScatterPoint(2009.27884615, 784388.558145);
|
||||
yield return new ScatterPoint(2009.66346154, 2308241.52676);
|
||||
yield return new ScatterPoint(2009.71153846, 1910952.97497);
|
||||
yield return new ScatterPoint(2010.19230769, 410469.838044);
|
||||
yield return new ScatterPoint(2010.38461538, 1309747.2643);
|
||||
yield return new ScatterPoint(2011.16, 1170000);
|
||||
yield return new ScatterPoint(2011.32, 2600000);
|
||||
yield return new ScatterPoint(2011.9, 1200000);
|
||||
yield return new ScatterPoint(2012.40, 2400000);
|
||||
yield return new ScatterPoint(2012.41, 2300000);
|
||||
yield return new ScatterPoint(2012.7, 2100000);
|
||||
yield return new ScatterPoint(2012.9, 1200000);
|
||||
yield return new ScatterPoint(2013.4, 5000000);
|
||||
yield return new ScatterPoint(2013.8, 4300000);
|
||||
yield return new ScatterPoint(2014.16, 4300000);
|
||||
yield return new ScatterPoint(2014.5, 4200000);
|
||||
yield return new ScatterPoint(2014.8, 2600000);
|
||||
yield return new ScatterPoint(2014.81, 3800000);
|
||||
yield return new ScatterPoint(2014.82, 5700000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="CandleStickAndVolumeSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("CandleStickAndVolumeSeries")]
|
||||
[Tags("Series")]
|
||||
public static class CandleStickAndVolumeSeriesExamples
|
||||
{
|
||||
[Example("Candles + Volume (combined volume), adjusting Y-axis")]
|
||||
public static Example CombinedVolume_Adjusting()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (combined volume)",
|
||||
VolumeStyle.Combined,
|
||||
naturalY: false,
|
||||
naturalV: false);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (combined volume), natural Y-axis")]
|
||||
public static Example CombinedVolume_Natural()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (combined volume)",
|
||||
VolumeStyle.Combined,
|
||||
naturalY: true,
|
||||
naturalV: true);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (stacked volume), adjusting Y-axis")]
|
||||
public static Example StackedVolume_Adjusting()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (stacked volume)",
|
||||
VolumeStyle.Stacked,
|
||||
naturalY: false,
|
||||
naturalV: false);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (stacked volume), natural Y-axis")]
|
||||
public static Example StackedVolume_Natural()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (stacked volume)",
|
||||
VolumeStyle.Stacked,
|
||||
naturalY: true,
|
||||
naturalV: true);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (+/- volume), adjusting Y-axis")]
|
||||
public static Example PosNegVolume_Adjusting()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (+/- volume)",
|
||||
VolumeStyle.PositiveNegative,
|
||||
naturalY: false,
|
||||
naturalV: false);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (+/- volume), natural Y-axis")]
|
||||
public static Example PosNegVolume_Natural()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (+/- volume)",
|
||||
VolumeStyle.PositiveNegative,
|
||||
naturalY: true,
|
||||
naturalV: true);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (volume not shown), adjusting Y-axis")]
|
||||
public static Example NoVolume_Adjusting()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (volume not shown)",
|
||||
VolumeStyle.None,
|
||||
naturalY: false,
|
||||
naturalV: false);
|
||||
}
|
||||
|
||||
[Example("Candles + Volume (volume not shown), natural Y-axis")]
|
||||
public static Example NoVolume_Natural()
|
||||
{
|
||||
return CreateCandleStickAndVolumeSeriesExample(
|
||||
"Candles + Volume (volume not shown)",
|
||||
VolumeStyle.None,
|
||||
naturalY: true,
|
||||
naturalV: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the candle stick and volume series example.
|
||||
/// </summary>
|
||||
/// <returns>The candle stick and volume series example.</returns>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="style">Style.</param>
|
||||
/// <param name="n">N.</param>
|
||||
/// <param name="naturalY">If set to <c>true</c> natural y.</param>
|
||||
/// <param name="naturalV">If set to <c>true</c> natural v.</param>
|
||||
private static Example CreateCandleStickAndVolumeSeriesExample(
|
||||
string title,
|
||||
VolumeStyle style,
|
||||
int n = 10000,
|
||||
bool naturalY = false,
|
||||
bool naturalV = false)
|
||||
{
|
||||
var pm = new PlotModel { Title = title };
|
||||
|
||||
var series = new CandleStickAndVolumeSeries
|
||||
{
|
||||
PositiveColor = OxyColors.DarkGreen,
|
||||
NegativeColor = OxyColors.Red,
|
||||
PositiveHollow = false,
|
||||
NegativeHollow = false,
|
||||
SeparatorColor = OxyColors.Gray,
|
||||
SeparatorLineStyle = LineStyle.Dash,
|
||||
VolumeStyle = style
|
||||
};
|
||||
|
||||
// create bars
|
||||
foreach (var bar in OhlcvItemGenerator.MRProcess(n))
|
||||
{
|
||||
series.Append(bar);
|
||||
}
|
||||
|
||||
// create visible window
|
||||
var Istart = n - 200;
|
||||
var Iend = n - 120;
|
||||
var Ymin = series.Items.Skip(Istart).Take(Iend - Istart + 1).Select(x => x.Low).Min();
|
||||
var Ymax = series.Items.Skip(Istart).Take(Iend - Istart + 1).Select(x => x.High).Max();
|
||||
var Xmin = series.Items[Istart].X;
|
||||
var Xmax = series.Items[Iend].X;
|
||||
|
||||
// setup axes
|
||||
var timeAxis = new DateTimeAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = Xmin,
|
||||
Maximum = Xmax
|
||||
};
|
||||
var barAxis = new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
Key = series.BarAxisKey,
|
||||
StartPosition = 0.25,
|
||||
EndPosition = 1.0,
|
||||
Minimum = naturalY ? double.NaN : Ymin,
|
||||
Maximum = naturalY ? double.NaN : Ymax
|
||||
};
|
||||
var volAxis = new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
Key = series.VolumeAxisKey,
|
||||
StartPosition = 0.0,
|
||||
EndPosition = 0.22,
|
||||
Minimum = naturalV ? double.NaN : 0,
|
||||
Maximum = naturalV ? double.NaN : 5000
|
||||
};
|
||||
|
||||
switch (style)
|
||||
{
|
||||
case VolumeStyle.None:
|
||||
barAxis.Key = null;
|
||||
barAxis.StartPosition = 0.0;
|
||||
pm.Axes.Add(timeAxis);
|
||||
pm.Axes.Add(barAxis);
|
||||
break;
|
||||
|
||||
case VolumeStyle.Combined:
|
||||
case VolumeStyle.Stacked:
|
||||
pm.Axes.Add(timeAxis);
|
||||
pm.Axes.Add(barAxis);
|
||||
pm.Axes.Add(volAxis);
|
||||
break;
|
||||
|
||||
case VolumeStyle.PositiveNegative:
|
||||
volAxis.Minimum = naturalV ? double.NaN : -5000;
|
||||
pm.Axes.Add(timeAxis);
|
||||
pm.Axes.Add(barAxis);
|
||||
pm.Axes.Add(volAxis);
|
||||
break;
|
||||
}
|
||||
|
||||
pm.Series.Add(series);
|
||||
|
||||
if (naturalY == false)
|
||||
{
|
||||
timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, barAxis);
|
||||
}
|
||||
|
||||
var controller = new PlotController();
|
||||
controller.UnbindAll();
|
||||
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
|
||||
return new Example(pm, controller);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the Y extent.
|
||||
/// </summary>
|
||||
/// <param name="series">Series.</param>
|
||||
/// <param name="xaxis">Xaxis.</param>
|
||||
/// <param name="yaxis">Yaxis.</param>
|
||||
private static void AdjustYExtent(CandleStickAndVolumeSeries series, DateTimeAxis xaxis, LinearAxis yaxis)
|
||||
{
|
||||
var xmin = xaxis.ActualMinimum;
|
||||
var xmax = xaxis.ActualMaximum;
|
||||
|
||||
var istart = series.FindByX(xmin);
|
||||
var iend = series.FindByX(xmax, istart);
|
||||
|
||||
var ymin = double.MaxValue;
|
||||
var ymax = double.MinValue;
|
||||
for (int i = istart; i <= iend; i++)
|
||||
{
|
||||
var bar = series.Items[i];
|
||||
ymin = Math.Min(ymin, bar.Low);
|
||||
ymax = Math.Max(ymax, bar.High);
|
||||
}
|
||||
|
||||
var extent = ymax - ymin;
|
||||
var margin = extent * 0.10;
|
||||
|
||||
yaxis.Zoom(ymin - margin, ymax + margin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="CandleStickSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("CandleStickSeries"), Tags("Series")]
|
||||
public static class CandleStickSeriesExamples
|
||||
{
|
||||
[Example("Large Data Set (wide window)")]
|
||||
public static Example LargeDataSetWide()
|
||||
{
|
||||
var pm = new PlotModel { Title = "Large Data Set (wide window)" };
|
||||
|
||||
var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom };
|
||||
pm.Axes.Add(timeSpanAxis1);
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
|
||||
pm.Axes.Add(linearAxis1);
|
||||
var n = 1000000;
|
||||
var items = HighLowItemGenerator.MRProcess(n).ToArray();
|
||||
var series = new CandleStickSeries
|
||||
{
|
||||
Color = OxyColors.Black,
|
||||
IncreasingColor = OxyColors.DarkGreen,
|
||||
DecreasingColor = OxyColors.Red,
|
||||
DataFieldX = "Time",
|
||||
DataFieldHigh = "H",
|
||||
DataFieldLow = "L",
|
||||
DataFieldOpen = "O",
|
||||
DataFieldClose = "C",
|
||||
TrackerFormatString =
|
||||
"High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
|
||||
ItemsSource = items
|
||||
};
|
||||
|
||||
timeSpanAxis1.Minimum = items[n - 200].X;
|
||||
timeSpanAxis1.Maximum = items[n - 130].X;
|
||||
|
||||
linearAxis1.Minimum = items.Skip(n - 200).Take(70).Select(x => x.Low).Min();
|
||||
linearAxis1.Maximum = items.Skip(n - 200).Take(70).Select(x => x.High).Max();
|
||||
|
||||
pm.Series.Add(series);
|
||||
|
||||
timeSpanAxis1.AxisChanged += (sender, e) => AdjustYExtent(series, timeSpanAxis1, linearAxis1);
|
||||
|
||||
var controller = new PlotController();
|
||||
controller.UnbindAll();
|
||||
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
|
||||
return new Example(pm, controller);
|
||||
}
|
||||
|
||||
[Example("Large Data Set (narrow window)")]
|
||||
public static Example LargeDataSetNarrow()
|
||||
{
|
||||
var pm = new PlotModel { Title = "Large Data Set (narrow window)" };
|
||||
|
||||
var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom };
|
||||
pm.Axes.Add(timeSpanAxis1);
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
|
||||
pm.Axes.Add(linearAxis1);
|
||||
var n = 1000000;
|
||||
var items = HighLowItemGenerator.MRProcess(n).ToArray();
|
||||
var series = new CandleStickSeries
|
||||
{
|
||||
Color = OxyColors.Black,
|
||||
IncreasingColor = OxyColors.DarkGreen,
|
||||
DecreasingColor = OxyColors.Red,
|
||||
TrackerFormatString =
|
||||
"High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
|
||||
ItemsSource = items
|
||||
};
|
||||
|
||||
|
||||
timeSpanAxis1.Minimum = items[0].X;
|
||||
timeSpanAxis1.Maximum = items[29].X;
|
||||
|
||||
linearAxis1.Minimum = items.Take(30).Select(x => x.Low).Min();
|
||||
linearAxis1.Maximum = items.Take(30).Select(x => x.High).Max();
|
||||
|
||||
pm.Series.Add(series);
|
||||
|
||||
timeSpanAxis1.AxisChanged += (sender, e) => AdjustYExtent(series, timeSpanAxis1, linearAxis1);
|
||||
|
||||
var controller = new PlotController();
|
||||
controller.UnbindAll();
|
||||
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
|
||||
return new Example(pm, controller);
|
||||
}
|
||||
|
||||
[Example("Small Set")]
|
||||
public static Example SmallDataSet()
|
||||
{
|
||||
var pm = new PlotModel { Title = "Small Data Set" };
|
||||
|
||||
var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom };
|
||||
pm.Axes.Add(timeSpanAxis1);
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
|
||||
pm.Axes.Add(linearAxis1);
|
||||
var n = 100;
|
||||
var items = HighLowItemGenerator.MRProcess(n).ToArray();
|
||||
var series = new CandleStickSeries
|
||||
{
|
||||
Color = OxyColors.Black,
|
||||
IncreasingColor = OxyColors.DarkGreen,
|
||||
DecreasingColor = OxyColors.Red,
|
||||
DataFieldX = "X",
|
||||
DataFieldHigh = "High",
|
||||
DataFieldLow = "Low",
|
||||
DataFieldOpen = "Open",
|
||||
DataFieldClose = "Close",
|
||||
TrackerFormatString =
|
||||
"High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
|
||||
ItemsSource = items
|
||||
};
|
||||
|
||||
pm.Series.Add(series);
|
||||
|
||||
timeSpanAxis1.AxisChanged += (sender, e) => AdjustYExtent(series, timeSpanAxis1, linearAxis1);
|
||||
|
||||
var controller = new PlotController();
|
||||
controller.UnbindAll();
|
||||
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
|
||||
return new Example(pm, controller);
|
||||
}
|
||||
|
||||
[Example("Simple CandleStickSeries example")]
|
||||
public static PlotModel SimpleExample()
|
||||
{
|
||||
var startTimeValue = DateTimeAxis.ToDouble(new DateTime(2016, 1, 1));
|
||||
var pm = new PlotModel { Title = "Simple CandleStickSeries example" };
|
||||
pm.Axes.Add(new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = startTimeValue - 7, Maximum = startTimeValue + 7 });
|
||||
pm.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var series = new CandleStickSeries();
|
||||
series.Items.Add(new HighLowItem(startTimeValue, 100, 80, 92, 94));
|
||||
series.Items.Add(new HighLowItem(startTimeValue + 1, 102, 77, 94, 93));
|
||||
series.Items.Add(new HighLowItem(startTimeValue + 2, 99, 85, 93, 93));
|
||||
pm.Series.Add(series);
|
||||
return pm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the Y extent.
|
||||
/// </summary>
|
||||
/// <param name="series">Series.</param>
|
||||
/// <param name="xaxis">Xaxis.</param>
|
||||
/// <param name="yaxis">Yaxis.</param>
|
||||
private static void AdjustYExtent(CandleStickSeries series, DateTimeAxis xaxis, LinearAxis yaxis)
|
||||
{
|
||||
var xmin = xaxis.ActualMinimum;
|
||||
var xmax = xaxis.ActualMaximum;
|
||||
|
||||
var istart = series.FindByX(xmin);
|
||||
var iend = series.FindByX(xmax, istart);
|
||||
|
||||
var ymin = double.MaxValue;
|
||||
var ymax = double.MinValue;
|
||||
for (int i = istart; i <= iend; i++)
|
||||
{
|
||||
var bar = series.Items[i];
|
||||
ymin = Math.Min(ymin, bar.Low);
|
||||
ymax = Math.Max(ymax, bar.High);
|
||||
}
|
||||
|
||||
var extent = ymax - ymin;
|
||||
var margin = extent * 0.10;
|
||||
|
||||
yaxis.Zoom(ymin - margin, ymax + margin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="HighLowItemGenerator.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Creates realistic high/low items.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
/// <summary>
|
||||
/// Creates realistic high/low items.
|
||||
/// </summary>
|
||||
public static class HighLowItemGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// The random number generator.
|
||||
/// </summary>
|
||||
private static readonly Random Rand = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Creates bars governed by a MR process
|
||||
/// </summary>
|
||||
/// <returns>The process.</returns>
|
||||
/// <param name="n">N.</param>
|
||||
/// <param name="x0">X0.</param>
|
||||
/// <param name="csigma">Csigma.</param>
|
||||
/// <param name="esigma">Esigma.</param>
|
||||
/// <param name="kappa">Kappa.</param>
|
||||
public static IEnumerable<HighLowItem> MRProcess(
|
||||
int n,
|
||||
double x0 = 100.0,
|
||||
double csigma = 0.50,
|
||||
double esigma = 0.70,
|
||||
double kappa = 0.01)
|
||||
{
|
||||
double x = x0;
|
||||
|
||||
var baseT = DateTime.UtcNow;
|
||||
for (int ti = 0; ti < n; ti++)
|
||||
{
|
||||
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma);
|
||||
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma);
|
||||
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma);
|
||||
|
||||
var open = x;
|
||||
var close = x = x + dx_c;
|
||||
var low = Min(open, close, open + dx_1, open + dx_2);
|
||||
var high = Max(open, close, open + dx_1, open + dx_2);
|
||||
|
||||
var nowT = baseT.AddSeconds(ti);
|
||||
var t = DateTimeAxis.ToDouble(nowT);
|
||||
yield return new HighLowItem(t, high, low, open, close);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the minimum of the specified a, b, c and d.
|
||||
/// </summary>
|
||||
/// <param name="a">A.</param>
|
||||
/// <param name="b">B.</param>
|
||||
/// <param name="c">C.</param>
|
||||
/// <param name="d">D.</param>
|
||||
/// <returns>The minimum.</returns>
|
||||
private static double Min(double a, double b, double c, double d)
|
||||
{
|
||||
return Math.Min(a, Math.Min(b, Math.Min(c, d)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the maximum of the specified a, b, c and d.
|
||||
/// </summary>
|
||||
/// <param name="a">A.</param>
|
||||
/// <param name="b">B.</param>
|
||||
/// <param name="c">C.</param>
|
||||
/// <param name="d">D.</param>
|
||||
/// <returns>The maximum.</returns>
|
||||
private static double Max(double a, double b, double c, double d)
|
||||
{
|
||||
return Math.Max(a, Math.Max(b, Math.Max(c, d)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get random normal
|
||||
/// </summary>
|
||||
/// <param name="mu">Mu.</param>
|
||||
/// <param name="sigma">Sigma.</param>
|
||||
private static double RandomNormal(double mu, double sigma)
|
||||
{
|
||||
return InverseCumNormal(Rand.NextDouble(), mu, sigma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fast approximation for inverse cum normal
|
||||
/// </summary>
|
||||
/// <param name="p">probability</param>
|
||||
/// <param name="mu">Mean</param>
|
||||
/// <param name="sigma">std dev</param>
|
||||
private static double InverseCumNormal(double p, double mu, double sigma)
|
||||
{
|
||||
const double A1 = -3.969683028665376e+01;
|
||||
const double A2 = 2.209460984245205e+02;
|
||||
const double A3 = -2.759285104469687e+02;
|
||||
const double A4 = 1.383577518672690e+02;
|
||||
const double A5 = -3.066479806614716e+01;
|
||||
const double A6 = 2.506628277459239e+00;
|
||||
|
||||
const double B1 = -5.447609879822406e+01;
|
||||
const double B2 = 1.615858368580409e+02;
|
||||
const double B3 = -1.556989798598866e+02;
|
||||
const double B4 = 6.680131188771972e+01;
|
||||
const double B5 = -1.328068155288572e+01;
|
||||
|
||||
const double C1 = -7.784894002430293e-03;
|
||||
const double C2 = -3.223964580411365e-01;
|
||||
const double C3 = -2.400758277161838e+00;
|
||||
const double C4 = -2.549732539343734e+00;
|
||||
const double C5 = 4.374664141464968e+00;
|
||||
const double C6 = 2.938163982698783e+00;
|
||||
|
||||
const double D1 = 7.784695709041462e-03;
|
||||
const double D2 = 3.224671290700398e-01;
|
||||
const double D3 = 2.445134137142996e+00;
|
||||
const double D4 = 3.754408661907416e+00;
|
||||
|
||||
const double Xlow = 0.02425;
|
||||
const double Xhigh = 1.0 - Xlow;
|
||||
|
||||
double z, r;
|
||||
|
||||
if (p < Xlow)
|
||||
{
|
||||
// Rational approximation for the lower region 0<x<u_low
|
||||
z = Math.Sqrt(-2.0 * Math.Log(p));
|
||||
z = (((((C1 * z + C2) * z + C3) * z + C4) * z + C5) * z + C6) /
|
||||
((((D1 * z + D2) * z + D3) * z + D4) * z + 1.0);
|
||||
}
|
||||
else if (p <= Xhigh)
|
||||
{
|
||||
// Rational approximation for the central region u_low<=x<=u_high
|
||||
z = p - 0.5;
|
||||
r = z * z;
|
||||
z = (((((A1 * r + A2) * r + A3) * r + A4) * r + A5) * r + A6) * z /
|
||||
(((((B1 * r + B2) * r + B3) * r + B4) * r + B5) * r + 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rational approximation for the upper region u_high<x<1
|
||||
z = Math.Sqrt(-2.0 * Math.Log(1.0 - p));
|
||||
z = -(((((C1 * z + C2) * z + C3) * z + C4) * z + C5) * z + C6) /
|
||||
((((D1 * z + D2) * z + D3) * z + D4) * z + 1.0);
|
||||
}
|
||||
|
||||
// error (f_(z) - x) divided by the cumulative's derivative
|
||||
r = (CumN0(z) - p) * Math.Sqrt(2.0) * Math.Sqrt(Math.PI) * Math.Exp(0.5 * z * z);
|
||||
|
||||
// Halley's method
|
||||
z -= r / (1 + (0.5 * z * r));
|
||||
|
||||
return mu + (z * sigma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cumulative for a N(0,1) distribution
|
||||
/// </summary>
|
||||
/// <returns>The n0.</returns>
|
||||
/// <param name="x">The x coordinate.</param>
|
||||
private static double CumN0(double x)
|
||||
{
|
||||
const double B1 = 0.319381530;
|
||||
const double B2 = -0.356563782;
|
||||
const double B3 = 1.781477937;
|
||||
const double B4 = -1.821255978;
|
||||
const double B5 = 1.330274429;
|
||||
const double P = 0.2316419;
|
||||
const double C = 0.39894228;
|
||||
|
||||
if (x >= 0.0)
|
||||
{
|
||||
double t = 1.0 / (1.0 + (P * x));
|
||||
return (1.0 - C * Math.Exp(-x * x / 2.0) * t * (t * (t * (t * (t * B5 + B4) + B3) + B2) + B1));
|
||||
}
|
||||
else
|
||||
{
|
||||
double t = 1.0 / (1.0 - P * x);
|
||||
return (C * Math.Exp(-x * x / 2.0) * t * (t * (t * (t * (t * B5 + B4) + B3) + B2) + B1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="HighLowSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("HighLowSeries"), Tags("Series")]
|
||||
public static class HighLowSeriesExamples
|
||||
{
|
||||
[Example("HighLowSeries")]
|
||||
public static PlotModel HighLowSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "HighLowSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new HighLowSeries { Title = "HighLowSeries 1", Color = OxyColors.Black, };
|
||||
var r = new Random(314);
|
||||
var price = 100.0;
|
||||
for (int x = 0; x < 24; x++)
|
||||
{
|
||||
price = price + r.NextDouble() + 0.1;
|
||||
var high = price + 10 + r.NextDouble() * 10;
|
||||
var low = price - (10 + r.NextDouble() * 10);
|
||||
var open = low + r.NextDouble() * (high - low);
|
||||
var close = low + r.NextDouble() * (high - low);
|
||||
s1.Items.Add(new HighLowItem(x, high, low, open, close));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("HighLowSeries (reversed X Axis)")]
|
||||
public static PlotModel HighLowSeriesReversedXAxis()
|
||||
{
|
||||
return HighLowSeries().ReverseXAxis();
|
||||
}
|
||||
|
||||
[Example("HighLowSeries (DateTime axis)")]
|
||||
public static PlotModel HighLowSeriesDateTimeAxis()
|
||||
{
|
||||
var m = new PlotModel();
|
||||
var x0 = DateTimeAxis.ToDouble(new DateTime(2013, 05, 04));
|
||||
var a = new DateTimeAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = x0 - 0.9,
|
||||
Maximum = x0 + 1.9,
|
||||
IntervalType = DateTimeIntervalType.Days,
|
||||
MajorStep = 1,
|
||||
MinorStep = 1,
|
||||
StringFormat = "yyyy-MM-dd"
|
||||
};
|
||||
m.Axes.Add(a);
|
||||
var s = new HighLowSeries
|
||||
{
|
||||
TrackerFormatString =
|
||||
"X: {1:yyyy-MM-dd}\nHigh: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}"
|
||||
};
|
||||
|
||||
s.Items.Add(new HighLowItem(x0, 14, 10, 13, 12.4));
|
||||
s.Items.Add(new HighLowItem(x0 + 1, 17, 8, 12.4, 16.3));
|
||||
m.Series.Add(s);
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="OhlcvItemGenerator.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Creates realistic OHLCV items.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
/// <summary>
|
||||
/// Creates realistic OHLCV items.
|
||||
/// </summary>
|
||||
public static class OhlcvItemGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// The random number generator.
|
||||
/// </summary>
|
||||
private static readonly Random Rand = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Creates bars governed by a MR process.
|
||||
/// </summary>
|
||||
/// <param name="n">N.</param>
|
||||
/// <param name="x0">X0.</param>
|
||||
/// <param name="v0">V0.</param>
|
||||
/// <param name="csigma">Csigma.</param>
|
||||
/// <param name="esigma">Esigma.</param>
|
||||
/// <param name="kappa">Kappa.</param>
|
||||
/// <returns>
|
||||
/// The process.
|
||||
/// </returns>
|
||||
public static IEnumerable<OhlcvItem> MRProcess(
|
||||
int n,
|
||||
double x0 = 100.0,
|
||||
double v0 = 500,
|
||||
double csigma = 0.50,
|
||||
double esigma = 0.75,
|
||||
double kappa = 0.01)
|
||||
{
|
||||
double x = x0;
|
||||
var baseT = DateTime.UtcNow;
|
||||
for (int ti = 0; ti < n; ti++)
|
||||
{
|
||||
var dx_c = -kappa * (x - x0) + RandomNormal(0, csigma);
|
||||
var dx_1 = -kappa * (x - x0) + RandomNormal(0, esigma);
|
||||
var dx_2 = -kappa * (x - x0) + RandomNormal(0, esigma);
|
||||
|
||||
var open = x;
|
||||
var close = x = x + dx_c;
|
||||
var low = Min(open, close, open + dx_1, open + dx_2);
|
||||
var high = Max(open, close, open + dx_1, open + dx_2);
|
||||
|
||||
var dp = close - open;
|
||||
var v = v0 * Math.Exp(Math.Abs(dp) / csigma);
|
||||
var dir = (dp < 0) ?
|
||||
-Math.Min(-dp / esigma, 1.0) :
|
||||
Math.Min(dp / esigma, 1.0);
|
||||
|
||||
var skew = (dir + 1) / 2.0;
|
||||
var buyvol = skew * v;
|
||||
var sellvol = (1 - skew) * v;
|
||||
|
||||
var nowT = baseT.AddSeconds(ti);
|
||||
var t = DateTimeAxis.ToDouble(nowT);
|
||||
yield return new OhlcvItem(t, open, high, low, close, buyvol, sellvol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the minimum of the specified a, b, c and d.
|
||||
/// </summary>
|
||||
/// <param name="a">A.</param>
|
||||
/// <param name="b">B.</param>
|
||||
/// <param name="c">C.</param>
|
||||
/// <param name="d">D.</param>
|
||||
/// <returns>The minimum.</returns>
|
||||
private static double Min(double a, double b, double c, double d)
|
||||
{
|
||||
return Math.Min(a, Math.Min(b, Math.Min(c, d)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the maximum of the specified a, b, c and d.
|
||||
/// </summary>
|
||||
/// <param name="a">A.</param>
|
||||
/// <param name="b">B.</param>
|
||||
/// <param name="c">C.</param>
|
||||
/// <param name="d">D.</param>
|
||||
/// <returns>The maximum.</returns>
|
||||
private static double Max(double a, double b, double c, double d)
|
||||
{
|
||||
return Math.Max(a, Math.Max(b, Math.Max(c, d)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets random normal
|
||||
/// </summary>
|
||||
/// <param name="mu">Mu.</param>
|
||||
/// <param name="sigma">Sigma.</param>
|
||||
/// <returns></returns>
|
||||
private static double RandomNormal(double mu, double sigma)
|
||||
{
|
||||
return InverseCumNormal(Rand.NextDouble(), mu, sigma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fast approximation for inverse cum normal
|
||||
/// </summary>
|
||||
/// <param name="p">probability</param>
|
||||
/// <param name="mu">Mean</param>
|
||||
/// <param name="sigma">std dev</param>
|
||||
private static double InverseCumNormal(double p, double mu, double sigma)
|
||||
{
|
||||
const double A1 = -3.969683028665376e+01;
|
||||
const double A2 = 2.209460984245205e+02;
|
||||
const double A3 = -2.759285104469687e+02;
|
||||
const double A4 = 1.383577518672690e+02;
|
||||
const double A5 = -3.066479806614716e+01;
|
||||
const double A6 = 2.506628277459239e+00;
|
||||
|
||||
const double B1 = -5.447609879822406e+01;
|
||||
const double B2 = 1.615858368580409e+02;
|
||||
const double B3 = -1.556989798598866e+02;
|
||||
const double B4 = 6.680131188771972e+01;
|
||||
const double B5 = -1.328068155288572e+01;
|
||||
|
||||
const double C1 = -7.784894002430293e-03;
|
||||
const double C2 = -3.223964580411365e-01;
|
||||
const double C3 = -2.400758277161838e+00;
|
||||
const double C4 = -2.549732539343734e+00;
|
||||
const double C5 = 4.374664141464968e+00;
|
||||
const double C6 = 2.938163982698783e+00;
|
||||
|
||||
const double D1 = 7.784695709041462e-03;
|
||||
const double D2 = 3.224671290700398e-01;
|
||||
const double D3 = 2.445134137142996e+00;
|
||||
const double D4 = 3.754408661907416e+00;
|
||||
|
||||
const double Xlow = 0.02425;
|
||||
const double Xhigh = 1.0 - Xlow;
|
||||
|
||||
double z, r;
|
||||
|
||||
if (p < Xlow)
|
||||
{
|
||||
// Rational approximation for the lower region 0<x<u_low
|
||||
z = Math.Sqrt(-2.0 * Math.Log(p));
|
||||
z = (((((C1 * z + C2) * z + C3) * z + C4) * z + C5) * z + C6) /
|
||||
((((D1 * z + D2) * z + D3) * z + D4) * z + 1.0);
|
||||
}
|
||||
else if (p <= Xhigh)
|
||||
{
|
||||
// Rational approximation for the central region u_low<=x<=u_high
|
||||
z = p - 0.5;
|
||||
r = z * z;
|
||||
z = (((((A1 * r + A2) * r + A3) * r + A4) * r + A5) * r + A6) * z /
|
||||
(((((B1 * r + B2) * r + B3) * r + B4) * r + B5) * r + 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rational approximation for the upper region u_high<x<1
|
||||
z = Math.Sqrt(-2.0 * Math.Log(1.0 - p));
|
||||
z = -(((((C1 * z + C2) * z + C3) * z + C4) * z + C5) * z + C6) /
|
||||
((((D1 * z + D2) * z + D3) * z + D4) * z + 1.0);
|
||||
}
|
||||
|
||||
// error (f_(z) - x) divided by the cumulative's derivative
|
||||
r = (CumN0(z) - p) * Math.Sqrt(2.0) * Math.Sqrt(Math.PI) * Math.Exp(0.5 * z * z);
|
||||
|
||||
// Halley's method
|
||||
z -= r / (1 + (0.5 * z * r));
|
||||
|
||||
return mu + (z * sigma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cumulative for a N(0,1) distribution
|
||||
/// </summary>
|
||||
/// <returns>The n0.</returns>
|
||||
/// <param name="x">The x coordinate.</param>
|
||||
private static double CumN0(double x)
|
||||
{
|
||||
const double B1 = 0.319381530;
|
||||
const double B2 = -0.356563782;
|
||||
const double B3 = 1.781477937;
|
||||
const double B4 = -1.821255978;
|
||||
const double B5 = 1.330274429;
|
||||
const double P = 0.2316419;
|
||||
const double C = 0.39894228;
|
||||
|
||||
if (x >= 0.0)
|
||||
{
|
||||
double t = 1.0 / (1.0 + (P * x));
|
||||
return (1.0 - C * Math.Exp(-x * x / 2.0) * t * (t * (t * (t * (t * B5 + B4) + B3) + B2) + B1));
|
||||
}
|
||||
else
|
||||
{
|
||||
double t = 1.0 / (1.0 - P * x);
|
||||
return (C * Math.Exp(-x * x / 2.0) * t * (t * (t * (t * (t * B5 + B4) + B3) + B2) + B1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="OldCandleStickSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("Old CandleStickSeries"), Tags("Series")]
|
||||
[Obsolete]
|
||||
public static class OldCandleStickSeriesExamples
|
||||
{
|
||||
[Example("CandleStickSeries")]
|
||||
public static PlotModel CandleStickSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "CandleStickSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new OldCandleStickSeries
|
||||
{
|
||||
Title = "CandleStickSeries 1",
|
||||
Color = OxyColors.Black,
|
||||
};
|
||||
var r = new Random(314);
|
||||
var price = 100.0;
|
||||
for (int x = 0; x < 16; x++)
|
||||
{
|
||||
price = price + r.NextDouble() + 0.1;
|
||||
var high = price + 10 + (r.NextDouble() * 10);
|
||||
var low = price - (10 + (r.NextDouble() * 10));
|
||||
var open = low + (r.NextDouble() * (high - low));
|
||||
var close = low + (r.NextDouble() * (high - low));
|
||||
s1.Items.Add(new HighLowItem(x, high, low, open, close));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MaximumPadding = 0.03, MinimumPadding = 0.03 });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("CandleStickSeries (red/green)")]
|
||||
public static PlotModel CandleStickSeriesRedGreen()
|
||||
{
|
||||
var model = CandleStickSeries();
|
||||
model.Title = "CandleStickSeries (red/green)";
|
||||
var s1 = (OldCandleStickSeries)model.Series[0];
|
||||
s1.IncreasingFill = OxyColors.DarkGreen;
|
||||
s1.DecreasingFill = OxyColors.Red;
|
||||
s1.ShadowEndColor = OxyColors.Gray;
|
||||
s1.Color = OxyColors.Black;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Minute data (DateTimeAxis)")]
|
||||
public static PlotModel MinuteData_DateTimeAxis()
|
||||
{
|
||||
var pm = new PlotModel { Title = "Minute Data (DateTimeAxis)" };
|
||||
|
||||
var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom, StringFormat = "hh:mm" };
|
||||
pm.Axes.Add(timeSpanAxis1);
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
|
||||
pm.Axes.Add(linearAxis1);
|
||||
var candleStickSeries = new OldCandleStickSeries
|
||||
{
|
||||
CandleWidth = 6,
|
||||
Color = OxyColors.Black,
|
||||
IncreasingFill = OxyColors.DarkGreen,
|
||||
DecreasingFill = OxyColors.Red,
|
||||
DataFieldX = "Time",
|
||||
DataFieldHigh = "H",
|
||||
DataFieldLow = "L",
|
||||
DataFieldOpen = "O",
|
||||
DataFieldClose = "C",
|
||||
TrackerFormatString = "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
|
||||
ItemsSource = lst
|
||||
};
|
||||
pm.Series.Add(candleStickSeries);
|
||||
return pm;
|
||||
}
|
||||
|
||||
private static List<MinuteRec> lst = new List<MinuteRec>
|
||||
{
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:31:00"), O = 1672.5000, H = 1673.5000, L = 1671.7500, C = 1672.7500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:32:00"), O = 1672.5000, H = 1673.5000, L = 1672.5000, C = 1672.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:33:00"), O = 1672.5000, H = 1672.7500, L = 1670.7500, C = 1671.2500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:34:00"), O = 1671.2500, H = 1671.2500, L = 1670.2500, C = 1670.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:35:00"), O = 1670.7500, H = 1671.7500, L = 1670.5000, C = 1671.2500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:36:00"), O = 1671.0000, H = 1672.5000, L = 1671.0000, C = 1672.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:37:00"), O = 1672.5000, H = 1673.0000, L = 1672.0000, C = 1673.0000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:38:00"), O = 1672.7500, H = 1673.2500, L = 1672.5000, C = 1672.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:39:00"), O = 1672.5000, H = 1672.7500, L = 1671.2500, C = 1671.2500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:40:00"), O = 1671.2500, H = 1672.5000, L = 1671.0000, C = 1672.0000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:41:00"), O = 1672.2500, H = 1672.5000, L = 1671.2500, C = 1672.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:42:00"), O = 1672.2500, H = 1672.5000, L = 1671.5000, C = 1671.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:43:00"), O = 1671.5000, H = 1671.7500, L = 1670.5000, C = 1671.0000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:44:00"), O = 1670.7500, H = 1671.7500, L = 1670.7500, C = 1671.7500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:45:00"), O = 1672.0000, H = 1672.2500, L = 1671.5000, C = 1671.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:46:00"), O = 1671.7500, H = 1671.7500, L = 1671.0000, C = 1671.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:47:00"), O = 1671.7500, H = 1672.2500, L = 1671.5000, C = 1671.7500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:48:00"), O = 1671.7500, H = 1672.7500, L = 1671.7500, C = 1672.5000 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:49:00"), O = 1672.2500, H = 1673.7500, L = 1672.2500, C = 1673.7500 },
|
||||
new MinuteRec { QTime = TimeSpan.Parse("06:50:00"), O = 1673.7500, H = 1675.0000, L = 1673.5000, C = 1675.0000 }
|
||||
};
|
||||
|
||||
[Example("Minute data (TimeSpanAxis)")]
|
||||
public static PlotModel MinuteData_TimeSpan()
|
||||
{
|
||||
var pm = new PlotModel { Title = "Minute Data (TimeSpanAxis)" };
|
||||
|
||||
var timeSpanAxis1 = new TimeSpanAxis { Position = AxisPosition.Bottom, StringFormat = "hh:mm" };
|
||||
pm.Axes.Add(timeSpanAxis1);
|
||||
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
|
||||
pm.Axes.Add(linearAxis1);
|
||||
var candleStickSeries = new OldCandleStickSeries
|
||||
{
|
||||
CandleWidth = 5,
|
||||
Color = OxyColors.DarkGray,
|
||||
IncreasingFill = OxyColors.DarkGreen,
|
||||
DecreasingFill = OxyColors.Red,
|
||||
DataFieldX = "QTime",
|
||||
DataFieldHigh = "H",
|
||||
DataFieldLow = "L",
|
||||
DataFieldOpen = "O",
|
||||
DataFieldClose = "C",
|
||||
TrackerFormatString = "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
|
||||
ItemsSource = lst
|
||||
};
|
||||
pm.Series.Add(candleStickSeries);
|
||||
return pm;
|
||||
}
|
||||
|
||||
public class MinuteRec
|
||||
{
|
||||
public DateTime Time { get { return new DateTime(2013, 10, 8) + this.QTime; } }
|
||||
public TimeSpan QTime { get; set; }
|
||||
public double H { get; set; }
|
||||
public double L { get; set; }
|
||||
public double O { get; set; }
|
||||
public double C { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="VolumeSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("VolumeSeries")]
|
||||
[Tags("Series")]
|
||||
public static class VolumeSeriesExamples
|
||||
{
|
||||
[Example("Just Volume (combined), fixed axis")]
|
||||
public static Example JustVolumeCombined_Fixed()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (combined)", VolumeStyle.Combined, natural: false);
|
||||
}
|
||||
|
||||
[Example("Just Volume (combined), natural axis")]
|
||||
public static Example JustVolumeCombined_Natural()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (combined)", VolumeStyle.Combined, natural: true);
|
||||
}
|
||||
|
||||
[Example("Just Volume (stacked), fixed axis")]
|
||||
public static Example JustVolumeStacked_Fixed()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (stacked)", VolumeStyle.Stacked, natural: false);
|
||||
}
|
||||
|
||||
[Example("Just Volume (stacked), natural axis")]
|
||||
public static Example JustVolumeStacked_Natural()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (stacked)", VolumeStyle.Stacked, natural: true);
|
||||
}
|
||||
|
||||
[Example("Just Volume (+/-), fixed axis")]
|
||||
public static Example JustVolumePositiveNegative_Fixed()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (+/-)", VolumeStyle.PositiveNegative, natural: false);
|
||||
}
|
||||
|
||||
[Example("Just Volume (+/-), natural axis")]
|
||||
public static Example JustVolumePositiveNegative_Natural()
|
||||
{
|
||||
return CreateVolumeSeries("Just Volume (+/-)", VolumeStyle.PositiveNegative, natural: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the volume series.
|
||||
/// </summary>
|
||||
/// <returns>The volume series.</returns>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="style">Style.</param>
|
||||
/// <param name="n">N.</param>
|
||||
/// <param name="natural">If set to <c>true</c> natural.</param>
|
||||
/// <param name="transposed">If set to <c>true</c> transposed.</param>
|
||||
private static Example CreateVolumeSeries(
|
||||
string title,
|
||||
VolumeStyle style,
|
||||
int n = 10000,
|
||||
bool natural = false)
|
||||
{
|
||||
var pm = new PlotModel { Title = title };
|
||||
|
||||
var series = new VolumeSeries
|
||||
{
|
||||
PositiveColor = OxyColors.DarkGreen,
|
||||
NegativeColor = OxyColors.Red,
|
||||
PositiveHollow = false,
|
||||
NegativeHollow = false,
|
||||
VolumeStyle = style,
|
||||
Title = "VolumeSeries",
|
||||
};
|
||||
|
||||
// create bars
|
||||
foreach (var bar in OhlcvItemGenerator.MRProcess(n))
|
||||
{
|
||||
series.Append(bar);
|
||||
}
|
||||
|
||||
// create visible window
|
||||
var Istart = n - 200;
|
||||
var Iend = n - 120;
|
||||
var Xmin = series.Items[Istart].X;
|
||||
var Xmax = series.Items[Iend].X;
|
||||
|
||||
// setup axes
|
||||
var timeAxis = new DateTimeAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = Xmin,
|
||||
Maximum = Xmax
|
||||
};
|
||||
|
||||
var volAxis = new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
StartPosition = 0.0,
|
||||
EndPosition = 1.0,
|
||||
Minimum = natural ? double.NaN : 0,
|
||||
Maximum = natural ? double.NaN : 10000
|
||||
};
|
||||
|
||||
switch (style)
|
||||
{
|
||||
case VolumeStyle.Combined:
|
||||
case VolumeStyle.Stacked:
|
||||
pm.Axes.Add(timeAxis);
|
||||
pm.Axes.Add(volAxis);
|
||||
break;
|
||||
|
||||
case VolumeStyle.PositiveNegative:
|
||||
volAxis.Minimum = natural ? double.NaN : -10000;
|
||||
pm.Axes.Add(timeAxis);
|
||||
pm.Axes.Add(volAxis);
|
||||
break;
|
||||
}
|
||||
|
||||
pm.Series.Add(series);
|
||||
|
||||
var controller = new PlotController();
|
||||
controller.UnbindAll();
|
||||
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
|
||||
return new Example(pm, controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
330
Source/Examples/ExampleLibrary/Series/FunctionSeriesExamples.cs
Normal file
330
Source/Examples/ExampleLibrary/Series/FunctionSeriesExamples.cs
Normal file
@@ -0,0 +1,330 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="FunctionSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Annotations;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("FunctionSeries"), Tags("Series")]
|
||||
public class FunctionSeriesExamples
|
||||
{
|
||||
[Example("Square wave")]
|
||||
public static PlotModel SquareWave()
|
||||
{
|
||||
return CreateSquareWave(25);
|
||||
}
|
||||
|
||||
private static PlotModel CreateSquareWave(int n = 25)
|
||||
{
|
||||
var plot = new PlotModel { Title = "Square wave (Gibbs phenomenon)" };
|
||||
|
||||
Func<double, double> f = (x) =>
|
||||
{
|
||||
double y = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int j = i * 2 + 1;
|
||||
y += Math.Sin(j * x) / j;
|
||||
}
|
||||
return y;
|
||||
};
|
||||
|
||||
var fs = new FunctionSeries(f, -10, 10, 0.0001, "sin(x)+sin(3x)/3+sin(5x)/5+...+sin(" + (2 * n - 1) + ")/" + (2 * n - 1));
|
||||
|
||||
plot.Series.Add(fs);
|
||||
plot.Subtitle = "n = " + fs.Points.Count;
|
||||
|
||||
plot.Axes.Add(new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
Minimum = -4,
|
||||
Maximum = 4
|
||||
});
|
||||
plot.Axes.Add(new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom
|
||||
});
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
||||
[Example("Parametric function 1")]
|
||||
public static PlotModel Clover()
|
||||
{
|
||||
return CreateParametricPlot(
|
||||
t => 2 * Math.Cos(2 * t) * Math.Cos(t),
|
||||
t => 2 * Math.Cos(2 * t) * Math.Sin(t),
|
||||
// t=>-4*Math.Sin(2*t)*Math.Cos(t)-2*Math.Cos(2*t)*Math.Sin(t),
|
||||
// t=>-4*Math.Sin(2*t)*Math.Sin(t)+2*Math.Cos(2*t)*Math.Cos(t),))))
|
||||
0, Math.PI * 2, 1000,
|
||||
"Parametric function",
|
||||
"Using the CartesianAxes property",
|
||||
"2cos(2t)cos(t) , 2cos(2t)sin(t)");
|
||||
|
||||
}
|
||||
|
||||
[Example("Parametric function 2")]
|
||||
public static PlotModel ParametricFunction2()
|
||||
{
|
||||
return CreateParametricPlot(
|
||||
t => 3 * Math.Sin(5 * t),
|
||||
t => 3 * Math.Cos(3 * t),
|
||||
0, Math.PI * 2, 1000,
|
||||
"Parametric function",
|
||||
null,
|
||||
"3sin(5t) , 3cos(3t)");
|
||||
}
|
||||
|
||||
[Example("Parametric function 3")]
|
||||
public static PlotModel ParametricFunction3()
|
||||
{
|
||||
return CreateParametricPlot(
|
||||
t => 2 * Math.Cos(t) + Math.Cos(8 * t),
|
||||
t => 2 * Math.Sin(t) + Math.Sin(8 * t),
|
||||
0, Math.PI * 2, 1000,
|
||||
"Parametric function",
|
||||
null,
|
||||
"2cos(t)+cos(8t) , 2sin(t)+sin(8t)");
|
||||
}
|
||||
|
||||
[Example("Lemniscate of Bernoulli")]
|
||||
public static PlotModel LemniscateOfBernoulli()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Lemniscate_of_Bernoulli
|
||||
double a = 1;
|
||||
return CreateParametricPlot(
|
||||
t => a * Math.Sqrt(2) * Math.Cos(t) / (Math.Sin(t) * Math.Sin(t) + 1),
|
||||
t => a * Math.Sqrt(2) * Math.Cos(t) * Math.Sin(t) / (Math.Sin(t) * Math.Sin(t) + 1),
|
||||
0, Math.PI * 2, 1000, "Lemniscate of Bernoulli");
|
||||
}
|
||||
|
||||
[Example("Lemniscate of Gerono")]
|
||||
public static PlotModel LemniscateOfGerono()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Lemniscate_of_Gerono
|
||||
return CreateParametricPlot(t => Math.Cos(t), t => Math.Sin(2 * t) / 2, 0, Math.PI * 2, 1000, "Lemniscate of Gerono");
|
||||
}
|
||||
|
||||
[Example("Lissajous figure")]
|
||||
public static PlotModel LissajousFigure()
|
||||
{
|
||||
double a = 3;
|
||||
double b = 2;
|
||||
double delta = Math.PI / 2;
|
||||
// http://en.wikipedia.org/wiki/Lissajous_figure
|
||||
return CreateParametricPlot(t => Math.Sin(a * t + delta), t => Math.Sin(b * t), 0, Math.PI * 2, 1000, "Lissajous figure", null, "a=3, b=2, δ = π/2");
|
||||
}
|
||||
|
||||
[Example("Rose curve")]
|
||||
public static PlotModel RoseCurve()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Rose_curve
|
||||
|
||||
var m = new PlotModel
|
||||
{
|
||||
Title = "Rose curve",
|
||||
PlotType = PlotType.Polar,
|
||||
PlotAreaBorderThickness = new OxyThickness(0)
|
||||
};
|
||||
|
||||
m.Axes.Add(new AngleAxis
|
||||
{
|
||||
Minimum = 0,
|
||||
Maximum = Math.PI * 2,
|
||||
MajorStep = Math.PI / 4,
|
||||
MinorStep = Math.PI / 16,
|
||||
MajorGridlineStyle = LineStyle.Solid,
|
||||
FormatAsFractions = true,
|
||||
FractionUnit = Math.PI,
|
||||
FractionUnitSymbol = "π"
|
||||
});
|
||||
m.Axes.Add(new MagnitudeAxis() { MajorGridlineStyle = LineStyle.Solid });
|
||||
|
||||
int d = 4;
|
||||
int n = 3;
|
||||
double k = (double)n / d;
|
||||
m.Series.Add(new FunctionSeries(t => Math.Sin(k * t), t => t, 0, Math.PI * 2 * d, 1000, string.Format("d={0}, n={1}", d, n)));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Limaçon of Pascal")]
|
||||
[DocumentationExample("Series/FunctionSeries")]
|
||||
public static PlotModel LimaconOfPascal()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Lima%C3%A7on
|
||||
|
||||
var m = new PlotModel { Title = "Limaçon of Pascal", PlotType = PlotType.Cartesian };
|
||||
for (int a = 4; a <= 4; a++)
|
||||
for (int b = 0; b <= 10; b++)
|
||||
{
|
||||
m.Series.Add(
|
||||
new FunctionSeries(
|
||||
t => a / 2 + b * Math.Cos(t) + a / 2 * Math.Cos(2 * t),
|
||||
t => b * Math.Sin(t) + a / 2 * Math.Sin(2 * t),
|
||||
0,
|
||||
Math.PI * 2,
|
||||
1000,
|
||||
string.Format("a={0}, b={1}", a, b)));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Folium of Descartes")]
|
||||
public static PlotModel DescartesFolium()
|
||||
{
|
||||
// http://www.wolframalpha.com/input/?i=folium+of+Descartes
|
||||
|
||||
var m = new PlotModel { Title = "Folium of Descartes", PlotType = PlotType.Cartesian };
|
||||
m.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -3, Maximum = 3 });
|
||||
m.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -3, Maximum = 3 });
|
||||
double a = 1;
|
||||
m.Series.Add(new FunctionSeries(t => 3 * a * t / (t * t * t + 1), t => 3 * a * t * t / (t * t * t + 1), -30, 30, 1001, string.Format("a={0}", a)));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Trisectrix of Maclaurin")]
|
||||
public static PlotModel TrisectrixOfMaclaurin()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Trisectrix_of_Maclaurin
|
||||
// http://mathworld.wolfram.com/MaclaurinTrisectrix.html
|
||||
|
||||
var m = new PlotModel { Title = "Trisectrix of Maclaurin", PlotType = PlotType.Cartesian };
|
||||
double a = 1;
|
||||
m.Series.Add(new FunctionSeries(t => a * (t * t - 3) / (t * t + 1), t => a * t * (t * t - 3) / (t * t + 1), -5, 5, 1000));
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Fermat's spiral")]
|
||||
public static PlotModel FermatsSpiral()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Fermat's_spiral
|
||||
// http://www.wolframalpha.com/input/?i=Fermat%27s+spiral
|
||||
var m = new PlotModel { Title = "Fermat's spiral", PlotType = PlotType.Cartesian };
|
||||
double a = 1;
|
||||
m.Series.Add(new FunctionSeries(t => a * Math.Sqrt(t) * Math.Cos(t), t => a * Math.Sqrt(t) * Math.Sin(t), 0, 20, 1000));
|
||||
m.Series.Add(new FunctionSeries(t => -a * Math.Sqrt(t) * Math.Cos(t), t => -a * Math.Sqrt(t) * Math.Sin(t), 0, 20, 1000));
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Fish curve")]
|
||||
public static PlotModel FishCurve()
|
||||
{
|
||||
// http://www.wolframalpha.com/input/?i=fish+curve
|
||||
var m = new PlotModel { Title = "Fish curve", PlotType = PlotType.Cartesian };
|
||||
for (double a = 0.1; a < 1; a += 0.1)
|
||||
{
|
||||
m.Series.Add(new FunctionSeries(t => a * (Math.Cos(t) - Math.Sin(t) * Math.Sin(t) / Math.Sqrt(2)), t => a * Math.Cos(t) * Math.Sin(t), 0, 2 * Math.PI, 1000));
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("Heaviside step function")]
|
||||
public static PlotModel HeavisideStepFunction()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Heaviside_step_function
|
||||
|
||||
var m = new PlotModel { Title = "Heaviside step function", PlotType = PlotType.Cartesian };
|
||||
m.Series.Add(new FunctionSeries(x =>
|
||||
{
|
||||
// make a gap in the curve at x=0
|
||||
if (Math.Abs(x) < 1e-8) return double.NaN;
|
||||
return x < 0 ? 0 : 1;
|
||||
}, -2, 2, 0.001));
|
||||
m.Annotations.Add(new LineAnnotation { Type = LineAnnotationType.Vertical, Color = m.DefaultColors[0], X = 0, MinimumY = 0, MaximumY = 1 });
|
||||
return m;
|
||||
}
|
||||
|
||||
[Example("FunctionSeries")]
|
||||
public static PlotModel FunctionSeries()
|
||||
{
|
||||
var pm = new PlotModel
|
||||
{
|
||||
Title = "Trigonometric functions",
|
||||
Subtitle = "Example using the FunctionSeries",
|
||||
PlotType = PlotType.Cartesian,
|
||||
PlotAreaBackground = OxyColors.White
|
||||
};
|
||||
pm.Series.Add(new FunctionSeries(Math.Sin, -10, 10, 0.1, "sin(x)"));
|
||||
pm.Series.Add(new FunctionSeries(Math.Cos, -10, 10, 0.1, "cos(x)"));
|
||||
pm.Series.Add(new FunctionSeries(t => 5 * Math.Cos(t), t => 5 * Math.Sin(t), 0, 2 * Math.PI, 1000, "cos(t),sin(t)"));
|
||||
return pm;
|
||||
}
|
||||
|
||||
[Example("Squirqle")]
|
||||
public static PlotModel Squirqle()
|
||||
{
|
||||
var plot = new PlotModel { Title = "Squirqle", PlotType = PlotType.Cartesian };
|
||||
plot.Series.Add(CreateSuperellipseSeries(4, 1, 1));
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
||||
[Example("Superellipse n=20")]
|
||||
public static PlotModel Superellipse20()
|
||||
{
|
||||
var plot = new PlotModel { Title = "Superellipse", PlotType = PlotType.Cartesian };
|
||||
var s = CreateSuperellipseSeries(20, 1, 1);
|
||||
s.MarkerType = MarkerType.Circle;
|
||||
plot.Series.Add(s);
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
||||
[Example("Lamé curves")]
|
||||
public static PlotModel LameCurves()
|
||||
{
|
||||
var plot = new PlotModel { Title = "Lamé curves", PlotType = PlotType.Cartesian };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
plot.Legends.Add(l);
|
||||
|
||||
for (double n = 0.25; n < 2; n += 0.25)
|
||||
{
|
||||
plot.Series.Add(CreateSuperellipseSeries(n, 1, 1));
|
||||
}
|
||||
|
||||
for (double n = 2; n <= 8 + 1e-6; n += 1)
|
||||
{
|
||||
plot.Series.Add(CreateSuperellipseSeries(n, 1, 1));
|
||||
}
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
||||
public static FunctionSeries CreateSuperellipseSeries(double n, double a, double b)
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Superellipse
|
||||
return new FunctionSeries(
|
||||
t => a * Math.Sign(Math.Cos(t)) * Math.Pow(Math.Abs(Math.Cos(t)), 2 / n),
|
||||
t => b * Math.Sign(Math.Sin(t)) * Math.Pow(Math.Abs(Math.Sin(t)), 2 / n),
|
||||
0,
|
||||
Math.PI * 2,
|
||||
101,
|
||||
string.Format("n={0}, a={1}, b={2}", n, a, b));
|
||||
}
|
||||
|
||||
private static PlotModel CreateParametricPlot(Func<double, double> fx, Func<double, double> fy, double t0,
|
||||
double t1, int n, string title, string subtitle = null,
|
||||
string seriesTitle = null)
|
||||
{
|
||||
var plot = new PlotModel { Title = title, Subtitle = subtitle, PlotType = PlotType.Cartesian };
|
||||
plot.Series.Add(new FunctionSeries(fx, fy, t0, t1, n, seriesTitle));
|
||||
return plot;
|
||||
}
|
||||
}
|
||||
}
|
||||
452
Source/Examples/ExampleLibrary/Series/HeatMapSeriesExamples.cs
Normal file
452
Source/Examples/ExampleLibrary/Series/HeatMapSeriesExamples.cs
Normal file
@@ -0,0 +1,452 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="HeatMapSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Creates a simple example heat map from a 2×3 matrix.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("HeatMapSeries"), Tags("Series")]
|
||||
public class HeatMapSeriesExamples
|
||||
{
|
||||
[Example("Peaks")]
|
||||
[DocumentationExample("Series/HeatMapSeries")]
|
||||
public static PlotModel Peaks()
|
||||
{
|
||||
return CreatePeaks();
|
||||
}
|
||||
|
||||
public static PlotModel CreatePeaks(OxyPalette palette = null, bool includeContours = true, int n = 100)
|
||||
{
|
||||
double x0 = -3.1;
|
||||
double x1 = 3.1;
|
||||
double y0 = -3;
|
||||
double y1 = 3;
|
||||
Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
|
||||
var xvalues = ArrayBuilder.CreateVector(x0, x1, n);
|
||||
var yvalues = ArrayBuilder.CreateVector(y0, y1, n);
|
||||
var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);
|
||||
|
||||
var model = new PlotModel { Title = "Peaks" };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = palette ?? OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
|
||||
|
||||
var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
|
||||
model.Series.Add(hms);
|
||||
if (includeContours)
|
||||
{
|
||||
var cs = new ContourSeries
|
||||
{
|
||||
Color = OxyColors.Black,
|
||||
FontSize = 0,
|
||||
ContourLevelStep = 1,
|
||||
LabelBackground = OxyColors.Undefined,
|
||||
ColumnCoordinates = yvalues,
|
||||
RowCoordinates = xvalues,
|
||||
Data = peaksData
|
||||
};
|
||||
model.Series.Add(cs);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, interpolated")]
|
||||
public static PlotModel Interpolated()
|
||||
{
|
||||
return CreateExample("Interpolated", true);
|
||||
}
|
||||
|
||||
[Example("2×3, interpolated, cartesian axes")]
|
||||
public static PlotModel InterpolatedCartesian()
|
||||
{
|
||||
var model = CreateExample("Interpolated, cartesian axes", true);
|
||||
model.PlotType = PlotType.Cartesian;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, interpolated with two NaN values")]
|
||||
public static PlotModel InterpolatedWithNanValue()
|
||||
{
|
||||
var model = CreateExample("Interpolated including two NaN values", true);
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
hms.Data[0, 1] = double.NaN;
|
||||
hms.Data[1, 0] = double.NaN;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, interpolated with two NaN values, flat data")]
|
||||
public static PlotModel InterpolatedWithNanValueFlat()
|
||||
{
|
||||
var model = CreateExample("Interpolated including two NaN values, otherwise 4.71", true);
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
|
||||
double datum = 4.71d;
|
||||
hms.Data[0, 0] = datum;
|
||||
hms.Data[0, 1] = datum;
|
||||
hms.Data[0, 2] = datum;
|
||||
hms.Data[1, 0] = datum;
|
||||
hms.Data[1, 1] = datum;
|
||||
hms.Data[1, 2] = datum;
|
||||
|
||||
hms.Data[0, 1] = double.NaN;
|
||||
hms.Data[1, 0] = double.NaN;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, not interpolated")]
|
||||
public static PlotModel NotInterpolated()
|
||||
{
|
||||
return CreateExample("Not interpolated values", false);
|
||||
}
|
||||
|
||||
[Example("2×3, not interpolated with two NaN values")]
|
||||
public static PlotModel NotInterpolatedWithNanValue()
|
||||
{
|
||||
var model = CreateExample("Not interpolated values including two NaN values", false);
|
||||
var ca = (LinearColorAxis)model.Axes[0];
|
||||
ca.InvalidNumberColor = OxyColors.Transparent;
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
hms.Data[0, 1] = double.NaN;
|
||||
hms.Data[1, 0] = double.NaN;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, not interpolated with two NaN values, flat data")]
|
||||
public static PlotModel NotInterpolatedWithNanValueFlat()
|
||||
{
|
||||
var model = CreateExample("Not interpolated values including two NaN values, otherwise 4.71", false);
|
||||
var ca = (LinearColorAxis)model.Axes[0];
|
||||
ca.InvalidNumberColor = OxyColors.Transparent;
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
|
||||
double datum = 4.71d;
|
||||
hms.Data[0, 0] = datum;
|
||||
hms.Data[0, 1] = datum;
|
||||
hms.Data[0, 2] = datum;
|
||||
hms.Data[1, 0] = datum;
|
||||
hms.Data[1, 1] = datum;
|
||||
hms.Data[1, 2] = datum;
|
||||
|
||||
hms.Data[0, 1] = double.NaN;
|
||||
hms.Data[1, 0] = double.NaN;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, reversed x-axis")]
|
||||
public static PlotModel NotInterpolatedReversedX()
|
||||
{
|
||||
var model = CreateExample("Reversed x-axis", false);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 1, EndPosition = 0 });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, X0>X1")]
|
||||
public static PlotModel X0GreaterThanX1()
|
||||
{
|
||||
var model = CreateExample("X0>X1", false);
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
var tmp = hms.X0;
|
||||
hms.X0 = hms.X1;
|
||||
hms.X1 = tmp;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, reversed x-axis, X0>X1")]
|
||||
public static PlotModel ReversedX_X0GreaterThanX1()
|
||||
{
|
||||
var model = CreateExample("Reversed x-axis, X0>X1", false);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 1, EndPosition = 0 });
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
var tmp = hms.X0;
|
||||
hms.X0 = hms.X1;
|
||||
hms.X1 = tmp;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, reversed y-axis")]
|
||||
public static PlotModel NotInterpolatedReversedY()
|
||||
{
|
||||
var model = CreateExample("Reversed y-axis", false);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, Y0>Y1")]
|
||||
public static PlotModel Y0GreaterThanY1()
|
||||
{
|
||||
var model = CreateExample("Y0>Y1", false);
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
var tmp = hms.Y0;
|
||||
hms.Y0 = hms.Y1;
|
||||
hms.Y1 = tmp;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2×3, reversed y-axis, Y0>Y1")]
|
||||
public static PlotModel ReversedY_Y0GreaterThanY1()
|
||||
{
|
||||
var model = CreateExample("Reversed y-axis, Y0>Y1", false);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 });
|
||||
var hms = (HeatMapSeries)model.Series[0];
|
||||
var tmp = hms.Y0;
|
||||
hms.Y0 = hms.Y1;
|
||||
hms.Y1 = tmp;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("2x3, reversed x- and y-axis")]
|
||||
public static PlotModel NotInterpolatedReversedXY()
|
||||
{
|
||||
var model = CreateExample("Reversed x- and y-axis", false);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 1, EndPosition = 0 });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("3×3, diagonal (center defined)")]
|
||||
public static PlotModel Diagonal()
|
||||
{
|
||||
var data = new double[3, 3];
|
||||
data[0, 0] = 1;
|
||||
data[1, 1] = 1;
|
||||
data[2, 2] = 1;
|
||||
|
||||
var model = new PlotModel { Title = "Diagonal (center defined)" };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
|
||||
|
||||
// adding half cellwidth/cellheight to bounding box coordinates
|
||||
var hms = new HeatMapSeries { CoordinateDefinition = HeatMapCoordinateDefinition.Center, X0 = 0.5, X1 = 2.5, Y0 = 2.5, Y1 = 0.5, Data = data, Interpolate = false };
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("3×3, diagonal (edge defined)")]
|
||||
public static PlotModel Diagonal2()
|
||||
{
|
||||
var data = new double[3, 3];
|
||||
data[0, 0] = 1;
|
||||
data[1, 1] = 1;
|
||||
data[2, 2] = 1;
|
||||
|
||||
var model = new PlotModel { Title = "Diagonal (edge defined)" };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
|
||||
|
||||
// adding half cellwidth/cellheight to bounding box coordinates
|
||||
var hms = new HeatMapSeries { CoordinateDefinition = HeatMapCoordinateDefinition.Edge, X0 = 0, X1 = 3, Y0 = 3, Y1 = 0, Data = data, Interpolate = false };
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("6×6, diagonal")]
|
||||
public static PlotModel Diagonal_6X6()
|
||||
{
|
||||
var data = new double[6, 6];
|
||||
data[0, 0] = 1;
|
||||
data[1, 1] = 1;
|
||||
data[2, 2] = 1;
|
||||
data[3, 3] = 1;
|
||||
data[4, 4] = 1;
|
||||
data[5, 5] = 1;
|
||||
|
||||
var model = new PlotModel { Title = "Diagonal 6×6" };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
|
||||
|
||||
// note: the coordinates are specifying the centers of the edge cells
|
||||
var hms = new HeatMapSeries { X0 = 0, X1 = 5, Y0 = 5, Y1 = 0, Data = data, Interpolate = false };
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Confusion matrix")]
|
||||
public static PlotModel ConfusionMatrix()
|
||||
{
|
||||
// Example provided by Pau Climent Pérez
|
||||
// See also http://en.wikipedia.org/wiki/Confusion_matrix
|
||||
var data = new double[3, 3];
|
||||
|
||||
data[0, 0] = 1;
|
||||
data[1, 1] = 0.8;
|
||||
data[1, 2] = 0.2;
|
||||
data[2, 2] = 1;
|
||||
|
||||
// I guess this is where the confusion comes from?
|
||||
data = data.Transpose();
|
||||
|
||||
string[] cat1 = { "class A", "class B", "class C" };
|
||||
|
||||
var model = new PlotModel { Title = "Confusion Matrix" };
|
||||
|
||||
var palette = OxyPalette.Interpolate(50, OxyColors.White, OxyColors.Black);
|
||||
|
||||
var lca = new LinearColorAxis { Position = AxisPosition.Right, Palette = palette, HighColor = OxyColors.White, LowColor = OxyColors.White };
|
||||
model.Axes.Add(lca);
|
||||
|
||||
var axis1 = new CategoryAxis { Position = AxisPosition.Top, Title = "Actual class" };
|
||||
axis1.Labels.AddRange(cat1);
|
||||
model.Axes.Add(axis1);
|
||||
|
||||
// We invert this axis, so that they look "symmetrical"
|
||||
var axis2 = new CategoryAxis { Position = AxisPosition.Left, Title = "Predicted class" };
|
||||
axis2.Labels.AddRange(cat1);
|
||||
axis2.Angle = -90;
|
||||
axis2.StartPosition = 1;
|
||||
axis2.EndPosition = 0;
|
||||
|
||||
model.Axes.Add(axis2);
|
||||
|
||||
var hms = new HeatMapSeries
|
||||
{
|
||||
Data = data,
|
||||
Interpolate = false,
|
||||
LabelFontSize = 0.25,
|
||||
X0 = 0,
|
||||
X1 = data.GetLength(1) - 1,
|
||||
Y0 = 0,
|
||||
Y1 = data.GetLength(0) - 1,
|
||||
};
|
||||
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Logarithmic X, interpolated")]
|
||||
public static PlotModel LogXInterpolated()
|
||||
{
|
||||
var data = new double[11, 21];
|
||||
|
||||
double k = Math.Pow(2, 0.1);
|
||||
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
for (int j = 0; j < 21; j++)
|
||||
{
|
||||
data[i, j] = Math.Pow(k, (double)i) * (double)j / 40.0;
|
||||
}
|
||||
}
|
||||
|
||||
var model = new PlotModel { Title = "Logarithmic X, interpolated" };
|
||||
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Gray(500), HighColor = OxyColors.White, LowColor = OxyColors.Black });
|
||||
|
||||
var hms = new HeatMapSeries { X0 = 1.0, X1 = 2.0, Y0 = 0, Y1 = 20, Data = data, Interpolate = true };
|
||||
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Logarithmic X, discrete rectangles")]
|
||||
public static PlotModel LogXNotInterpolated()
|
||||
{
|
||||
var data = new double[11, 21];
|
||||
|
||||
double k = Math.Pow(2, 0.1);
|
||||
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
for (int j = 0; j < 21; j++)
|
||||
{
|
||||
data[i, j] = Math.Pow(k, (double)i) * (double)j / 40.0;
|
||||
}
|
||||
}
|
||||
|
||||
var model = new PlotModel { Title = "Logarithmic X, discrete rectangles" };
|
||||
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Gray(500), HighColor = OxyColors.White, LowColor = OxyColors.Black });
|
||||
|
||||
var hms = new HeatMapSeries { X0 = 1.0, X1 = 2.0, Y0 = 0, Y1 = 20, Data = data, Interpolate = false, RenderMethod = HeatMapRenderMethod.Rectangles, LabelFontSize = 0.4 };
|
||||
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("6×4, not transposed")]
|
||||
public static PlotModel Normal_6X4()
|
||||
{
|
||||
return Create6X4("Normal 6×4 Heatmap");
|
||||
}
|
||||
|
||||
private static PlotModel Create6X4(string title)
|
||||
{
|
||||
var data = new double[6, 4];
|
||||
|
||||
for (int i = 1; i <= 6; i++)
|
||||
{
|
||||
for (int j = 1; j <= 4; j++)
|
||||
{
|
||||
data[i - 1, j - 1] = i * j;
|
||||
}
|
||||
}
|
||||
|
||||
var model = new PlotModel { Title = title, Subtitle = "Note the positions of the axes" };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.White, LowColor = OxyColors.Black });
|
||||
model.Series.Add(new HeatMapSeries { X0 = 1, X1 = 6, Y0 = 1, Y1 = 4, Data = data, Interpolate = true, LabelFontSize = 0.2 });
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a simple example heat map from a 2×3 matrix.
|
||||
/// </summary>
|
||||
/// <param name="title">The title.</param>
|
||||
/// <param name="interpolate">Interpolate the HeatMapSeries if set to <c>true</c>.</param>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
private static PlotModel CreateExample(string title, bool interpolate)
|
||||
{
|
||||
var data = new double[2, 3];
|
||||
data[0, 0] = 0;
|
||||
data[0, 1] = 0.2;
|
||||
data[0, 2] = 0.4;
|
||||
data[1, 0] = 0.1;
|
||||
data[1, 1] = 0.3;
|
||||
data[1, 2] = 0.2;
|
||||
|
||||
var model = new PlotModel { Title = "HeatMapSeries", Subtitle = title };
|
||||
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
|
||||
|
||||
// adding half cellwidth/cellheight to bounding box coordinates
|
||||
var hms = new HeatMapSeries
|
||||
{
|
||||
CoordinateDefinition = HeatMapCoordinateDefinition.Center,
|
||||
X0 = 0.5,
|
||||
X1 = 1.5,
|
||||
Y0 = 0.5,
|
||||
Y1 = 2.5,
|
||||
Data = data,
|
||||
Interpolate = interpolate,
|
||||
LabelFontSize = 0.2,
|
||||
};
|
||||
|
||||
model.Series.Add(hms);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ArrayExtensions
|
||||
{
|
||||
public static double[,] Transpose(this double[,] input)
|
||||
{
|
||||
int m = input.GetLength(0);
|
||||
int n = input.GetLength(1);
|
||||
var output = new double[n, m];
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
output[j, i] = input[i, j];
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
293
Source/Examples/ExampleLibrary/Series/HistogramSeriesExamples.cs
Normal file
293
Source/Examples/ExampleLibrary/Series/HistogramSeriesExamples.cs
Normal file
@@ -0,0 +1,293 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="HistogramSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Creates example histograms
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Examples("HistogramSeries"), Tags("Series")]
|
||||
public class HistogramSeriesExamples
|
||||
{
|
||||
[Example("Exponential Distribution")]
|
||||
[DocumentationExample("Series/HistogramSeries")]
|
||||
public static PlotModel ExponentialDistribution()
|
||||
{
|
||||
return CreateExponentialDistribution();
|
||||
}
|
||||
|
||||
[Example("Exponential Distribution (logarithmic)")]
|
||||
[DocumentationExample("Series/HistogramSeries")]
|
||||
public static PlotModel ExponentialDistributionLogarithmicAxis()
|
||||
{
|
||||
return CreateExponentialDistribution(true);
|
||||
}
|
||||
|
||||
[Example("Exponential Distribution (logarithmic,with BaseValue)")]
|
||||
[DocumentationExample("Series/HistogramSeries")]
|
||||
public static PlotModel ExponentialDistributionLogarithmicAxisWithBaseValue()
|
||||
{
|
||||
return CreateExponentialDistribution(true, baseValue: 0.1);
|
||||
}
|
||||
|
||||
[Example("Label Placement")]
|
||||
public static PlotModel HistogramLabelPlacement()
|
||||
{
|
||||
var model = new PlotModel { Title = "Label Placement" };
|
||||
|
||||
var s1 = new HistogramSeries { LabelPlacement = LabelPlacement.Base, LabelFormatString = "Base", StrokeThickness = 1, LabelMargin = 5 };
|
||||
var s2 = new HistogramSeries { LabelPlacement = LabelPlacement.Inside, LabelFormatString = "Inside", StrokeThickness = 1, LabelMargin = 5 };
|
||||
var s3 = new HistogramSeries { LabelPlacement = LabelPlacement.Middle, LabelFormatString = "Middle", StrokeThickness = 1, LabelMargin = 5 };
|
||||
var s4 = new HistogramSeries { LabelPlacement = LabelPlacement.Outside, LabelFormatString = "Outside", StrokeThickness = 1, LabelMargin = 5 };
|
||||
|
||||
s1.Items.Add(new HistogramItem(1, 2, 4, 4));
|
||||
s1.Items.Add(new HistogramItem(2, 3, -4, 4));
|
||||
s2.Items.Add(new HistogramItem(3, 4, 2, 2));
|
||||
s2.Items.Add(new HistogramItem(4, 5, -2, 2));
|
||||
s3.Items.Add(new HistogramItem(5, 6, 3, 3));
|
||||
s3.Items.Add(new HistogramItem(6, 7, -3, 3));
|
||||
s4.Items.Add(new HistogramItem(7, 8, 1, 1));
|
||||
s4.Items.Add(new HistogramItem(8, 9, -1, -1));
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Series.Add(s2);
|
||||
model.Series.Add(s3);
|
||||
model.Series.Add(s4);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Label Placement (reversed Y Axis)")]
|
||||
public static PlotModel LabelPlacementReversed()
|
||||
{
|
||||
return HistogramLabelPlacement().ReverseYAxis();
|
||||
}
|
||||
|
||||
[Example("Label Format String")]
|
||||
public static PlotModel LabelFormatString()
|
||||
{
|
||||
var model = CreateDisconnectedBins();
|
||||
var hs = model.Series[0] as HistogramSeries;
|
||||
hs.LabelFormatString = "Start: {1:0.00}\nEnd: {2:0.00}\nValue: {0:0.00}\nArea: {3:0.00}\nCount: {4}";
|
||||
hs.LabelPlacement = LabelPlacement.Inside;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Custom Bins")]
|
||||
public static PlotModel CustomBins()
|
||||
{
|
||||
return CreateExponentialDistributionCustomBins();
|
||||
}
|
||||
|
||||
[Example("Disconnected Bins")]
|
||||
public static PlotModel DisconnectedBins()
|
||||
{
|
||||
return CreateDisconnectedBins();
|
||||
}
|
||||
|
||||
[Example("Normal Distribution Three Colors")]
|
||||
public static PlotModel NormalDistribution()
|
||||
{
|
||||
return CreateNormalDistribution();
|
||||
}
|
||||
|
||||
[Example("Individual Bin Colors")]
|
||||
public static PlotModel IndividualBinColors()
|
||||
{
|
||||
return CreateIndividualBinColors();
|
||||
}
|
||||
|
||||
[Example("Custom Item Mapping")]
|
||||
public static PlotModel CustomItemMapping()
|
||||
{
|
||||
var model = new PlotModel { Title = "Custom Item Mapping" };
|
||||
|
||||
var s = new HistogramSeries { Mapping = obj => (HistogramItem)obj, TrackerFormatString = "{Description}"};
|
||||
s.Items.Add(new CustomHistogramItem(1, 2, 4, 4, "Item 1"));
|
||||
s.Items.Add(new CustomHistogramItem(2, 3, -4, 4, "Item 2"));
|
||||
s.Items.Add(new CustomHistogramItem(3, 4, 2, 2, "Item 3"));
|
||||
s.Items.Add(new CustomHistogramItem(4, 5, -2, 2, "Item 4"));
|
||||
model.Series.Add(s);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public class CustomHistogramItem : HistogramItem
|
||||
{
|
||||
public CustomHistogramItem(double rangeStart, double rangeEnd, double area, int count, string description)
|
||||
: base(rangeStart, rangeEnd, area, count)
|
||||
{
|
||||
this.Description = description;
|
||||
}
|
||||
|
||||
public string Description { get; }
|
||||
}
|
||||
|
||||
public static PlotModel CreateExponentialDistribution(bool logarithmicYAxis = false, double mean = 1, int n = 10000, double baseValue = 0)
|
||||
{
|
||||
var model = new PlotModel { Title = logarithmicYAxis ? "Exponential Distribution (logarithmic)" : "Exponential Distribution", Subtitle = "Uniformly distributed bins (" + n + " samples)" };
|
||||
model.Axes.Add(
|
||||
logarithmicYAxis ?
|
||||
(Axis)new LogarithmicAxis { Position = AxisPosition.Left, Title = "Frequency"} :
|
||||
new LinearAxis { Position = AxisPosition.Left, Title = "Frequency" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "x" });
|
||||
|
||||
Random rnd = new Random(1);
|
||||
|
||||
HistogramSeries chs = new HistogramSeries();
|
||||
|
||||
var binningOptions = new BinningOptions(BinningOutlierMode.CountOutliers, BinningIntervalType.InclusiveLowerBound, BinningExtremeValueMode.ExcludeExtremeValues);
|
||||
var binBreaks = HistogramHelpers.CreateUniformBins(0, 5, 15);
|
||||
chs.Items.AddRange(HistogramHelpers.Collect(SampleExps(rnd, mean, n), binBreaks, binningOptions));
|
||||
chs.StrokeThickness = 1;
|
||||
chs.BaseValue = baseValue;
|
||||
chs.NegativeFillColor = OxyColors.Red;
|
||||
model.Series.Add(chs);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static PlotModel CreateExponentialDistributionCustomBins(double mean = 1, int n = 50000)
|
||||
{
|
||||
var model = new PlotModel { Title = "Exponential Distribution", Subtitle = "Custom bins (" + n + " samples)" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Frequency" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "x" });
|
||||
|
||||
Random rnd = new Random(1);
|
||||
|
||||
HistogramSeries chs = new HistogramSeries();
|
||||
|
||||
var binningOptions = new BinningOptions(BinningOutlierMode.CountOutliers, BinningIntervalType.InclusiveLowerBound, BinningExtremeValueMode.ExcludeExtremeValues);
|
||||
chs.Items.AddRange(HistogramHelpers.Collect(SampleExps(rnd, mean, n), new double[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0 }, binningOptions));
|
||||
chs.StrokeThickness = 1;
|
||||
chs.FillColor = OxyColors.Purple;
|
||||
model.Series.Add(chs);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static PlotModel CreateNormalDistribution(double mean = 0, double std = 1, int n = 1000000)
|
||||
{
|
||||
var model = new PlotModel { Title = $"Normal Distribution (μ={mean}, σ={std})", Subtitle = "95% of the distribution (" + n + " samples)" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Frequency" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "x" });
|
||||
|
||||
Random rnd = new Random(1);
|
||||
|
||||
HistogramSeries chs = new HistogramSeries();
|
||||
var binningOptions = new BinningOptions(BinningOutlierMode.CountOutliers, BinningIntervalType.InclusiveLowerBound, BinningExtremeValueMode.ExcludeExtremeValues);
|
||||
var binBreaks = HistogramHelpers.CreateUniformBins(-std * 4, std * 4, 100);
|
||||
chs.Items.AddRange(HistogramHelpers.Collect(SampleNormal(rnd, mean, std, n), binBreaks, binningOptions));
|
||||
chs.StrokeThickness = 1;
|
||||
|
||||
double LimitHi = mean + 1.96 * std;
|
||||
double LimitLo = mean - 1.96 * std;
|
||||
OxyColor ColorHi = OxyColors.DarkRed;
|
||||
OxyColor ColorLo = OxyColors.DarkRed;
|
||||
|
||||
chs.ColorMapping = (item) =>
|
||||
{
|
||||
if (item.RangeCenter > LimitHi)
|
||||
{
|
||||
return ColorHi;
|
||||
}
|
||||
else if (item.RangeCenter < LimitLo)
|
||||
{
|
||||
return ColorLo;
|
||||
}
|
||||
return chs.ActualFillColor;
|
||||
};
|
||||
|
||||
model.Series.Add(chs);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static PlotModel CreateDisconnectedBins()
|
||||
{
|
||||
var model = new PlotModel { Title = "Disconnected Bins" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Representation" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "x" });
|
||||
|
||||
HistogramSeries chs = new HistogramSeries();
|
||||
chs.Items.AddRange(new[] { new HistogramItem(0, 0.5, 10, 7), new HistogramItem(0.75, 1.0, 10, 7) });
|
||||
chs.LabelFormatString = "{0:0.00}";
|
||||
chs.LabelPlacement = LabelPlacement.Middle;
|
||||
model.Series.Add(chs);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static PlotModel CreateIndividualBinColors(double mean = 1, int n = 10000)
|
||||
{
|
||||
var model = new PlotModel { Title = "Individual Bin Colors", Subtitle = "Minimum is Red, Maximum is Green" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Frequency" });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Observation" });
|
||||
|
||||
Random rnd = new Random(1);
|
||||
|
||||
HistogramSeries chs = new HistogramSeries() { FillColor = OxyColors.Gray, RenderInLegend = true, Title = "Measurements" };
|
||||
|
||||
var binningOptions = new BinningOptions(BinningOutlierMode.CountOutliers, BinningIntervalType.InclusiveLowerBound, BinningExtremeValueMode.ExcludeExtremeValues);
|
||||
var binBreaks = HistogramHelpers.CreateUniformBins(0, 10, 20);
|
||||
var bins = HistogramHelpers.Collect(SampleUniform(rnd, 0, 10, 1000), binBreaks, binningOptions).OrderBy(b => b.Count).ToArray();
|
||||
bins.First().Color = OxyColors.Red;
|
||||
bins.Last().Color = OxyColors.Green;
|
||||
chs.Items.AddRange(bins);
|
||||
chs.StrokeThickness = 1;
|
||||
model.Series.Add(chs);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private static IEnumerable<double> SampleExps(Random rnd, double mean, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
yield return SampleExp(rnd, mean);
|
||||
}
|
||||
}
|
||||
|
||||
private static double SampleExp(Random rnd, double mean)
|
||||
{
|
||||
return Math.Log(1.0 - rnd.NextDouble()) / -mean;
|
||||
}
|
||||
|
||||
private static IEnumerable<double> SampleNormal(Random rnd, double mean, double std, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
yield return SampleNormal(rnd, mean, std);
|
||||
}
|
||||
}
|
||||
|
||||
private static double SampleNormal(Random rnd, double mean, double std)
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
|
||||
var u1 = 1.0 - rnd.NextDouble();
|
||||
var u2 = rnd.NextDouble();
|
||||
return Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2) * std + mean;
|
||||
}
|
||||
|
||||
private static IEnumerable<double> SampleUniform(Random rnd, double min, double max, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
yield return rnd.NextDouble() * (max - min) + min;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="IntervalBarSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("IntervalBarSeries"), Tags("Series")]
|
||||
public static class IntervalBarSeriesExamples
|
||||
{
|
||||
[Example("IntervalBarSeries")]
|
||||
[DocumentationExample("Series/IntervalBarSeries")]
|
||||
public static PlotModel IntervalBarSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "IntervalBarSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new IntervalBarSeries { Title = "IntervalBarSeries 1", LabelFormatString = "{0} - {1}"};
|
||||
s1.Items.Add(new IntervalBarItem { Start = 6, End = 8 });
|
||||
s1.Items.Add(new IntervalBarItem { Start = 4, End = 8 });
|
||||
s1.Items.Add(new IntervalBarItem { Start = 5, End = 11 });
|
||||
s1.Items.Add(new IntervalBarItem { Start = 4, End = 12 });
|
||||
model.Series.Add(s1);
|
||||
var s2 = new IntervalBarSeries { Title = "IntervalBarSeries 2", LabelFormatString = "{0} - {1}" };
|
||||
s2.Items.Add(new IntervalBarItem { Start = 8, End = 9 });
|
||||
s2.Items.Add(new IntervalBarItem { Start = 8, End = 10 });
|
||||
s2.Items.Add(new IntervalBarItem { Start = 11, End = 12 });
|
||||
s2.Items.Add(new IntervalBarItem { Start = 12, End = 12.5 });
|
||||
model.Series.Add(s2);
|
||||
|
||||
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
|
||||
categoryAxis.Labels.Add("Activity A");
|
||||
categoryAxis.Labels.Add("Activity B");
|
||||
categoryAxis.Labels.Add("Activity C");
|
||||
categoryAxis.Labels.Add("Activity D");
|
||||
var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1 };
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(valueAxis);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("IntervalBarSeries with various label types")]
|
||||
public static PlotModel IntervalBarSeriesWithLabels()
|
||||
{
|
||||
var model = new PlotModel { Title = "IntervalBarSeries" };
|
||||
var l = new Legend { LegendPlacement = LegendPlacement.Outside };
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new IntervalBarSeries { Title = "IntervalBarSeries 1", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Outside };
|
||||
s1.Items.Add(new IntervalBarItem { Start = 6, End = 8, CategoryIndex = 0 });
|
||||
s1.Items.Add(new IntervalBarItem { Start = 10, End = 12, CategoryIndex = 0 });
|
||||
model.Series.Add(s1);
|
||||
|
||||
var s2 = new IntervalBarSeries { Title = "IntervalBarSeries 2", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Inside };
|
||||
s2.Items.Add(new IntervalBarItem { Start = 4, End = 8, CategoryIndex = 1 });
|
||||
s2.Items.Add(new IntervalBarItem { Start = 10, End = 12, CategoryIndex = 1 });
|
||||
model.Series.Add(s2);
|
||||
|
||||
var s3 = new IntervalBarSeries { Title = "IntervalBarSeries 3", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Middle };
|
||||
s3.Items.Add(new IntervalBarItem { Start = 5, End = 11, CategoryIndex = 2 });
|
||||
s3.Items.Add(new IntervalBarItem { Start = 13, End = 17, CategoryIndex = 2 });
|
||||
model.Series.Add(s3);
|
||||
|
||||
var s4 = new IntervalBarSeries { Title = "IntervalBarSeries 4", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Base };
|
||||
s4.Items.Add(new IntervalBarItem { Start = 4, End = 12, CategoryIndex = 3 });
|
||||
s4.Items.Add(new IntervalBarItem { Start = 13, End = 17, CategoryIndex = 3 });
|
||||
model.Series.Add(s4);
|
||||
|
||||
var s5 = new IntervalBarSeries { Title = "IntervalBarSeries 5", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Outside, LabelAngle = -45 };
|
||||
s5.Items.Add(new IntervalBarItem { Start = 6, End = 8, CategoryIndex = 4 });
|
||||
s5.Items.Add(new IntervalBarItem { Start = 10, End = 12, CategoryIndex = 4 });
|
||||
model.Series.Add(s5);
|
||||
|
||||
var s6 = new IntervalBarSeries { Title = "IntervalBarSeries 6", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Inside, LabelAngle = -45 };
|
||||
s6.Items.Add(new IntervalBarItem { Start = 4, End = 8, CategoryIndex = 5 });
|
||||
s6.Items.Add(new IntervalBarItem { Start = 10, End = 12, CategoryIndex = 5 });
|
||||
model.Series.Add(s6);
|
||||
|
||||
var s7 = new IntervalBarSeries { Title = "IntervalBarSeries 7", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Middle, LabelAngle = -45 };
|
||||
s7.Items.Add(new IntervalBarItem { Start = 5, End = 11, CategoryIndex = 6 });
|
||||
s7.Items.Add(new IntervalBarItem { Start = 13, End = 17, CategoryIndex = 6 });
|
||||
model.Series.Add(s7);
|
||||
|
||||
var s8 = new IntervalBarSeries { Title = "IntervalBarSeries 8", LabelFormatString = "{0} - {1}", LabelPlacement = LabelPlacement.Base, LabelAngle = -45 };
|
||||
s8.Items.Add(new IntervalBarItem { Start = 4, End = 12, CategoryIndex = 7 });
|
||||
s8.Items.Add(new IntervalBarItem { Start = 13, End = 17, CategoryIndex = 7 });
|
||||
model.Series.Add(s8);
|
||||
|
||||
var categoryAxis = new CategoryAxis { Key = "CategoryAxis", Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 };
|
||||
categoryAxis.Labels.Add("Label Outside");
|
||||
categoryAxis.Labels.Add("Label Inside");
|
||||
categoryAxis.Labels.Add("Label Middle");
|
||||
categoryAxis.Labels.Add("Label Base");
|
||||
categoryAxis.Labels.Add("Label Outside (angled)");
|
||||
categoryAxis.Labels.Add("Label Inside (angled)");
|
||||
categoryAxis.Labels.Add("Label Middle (angled)");
|
||||
categoryAxis.Labels.Add("Label Base (angled)");
|
||||
|
||||
var valueAxis = new LinearAxis { Key = "ValueAxis", Position = AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1 };
|
||||
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(valueAxis);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
503
Source/Examples/ExampleLibrary/Series/LineSeriesExamples.cs
Normal file
503
Source/Examples/ExampleLibrary/Series/LineSeriesExamples.cs
Normal file
@@ -0,0 +1,503 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="LineSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("LineSeries"), Tags("Series")]
|
||||
public class LineSeriesExamples
|
||||
{
|
||||
private static readonly Random Randomizer = new Random(13);
|
||||
|
||||
[Example("Default style")]
|
||||
[DocumentationExample("Series/LineSeries")]
|
||||
public static PlotModel DefaultStyle()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with default style" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var lineSeries1 = CreateExampleLineSeries();
|
||||
lineSeries1.Title = "LineSeries 1";
|
||||
model.Series.Add(lineSeries1);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Custom style")]
|
||||
public static PlotModel CustomStyle()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with custom style" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var lineSeries1 = CreateExampleLineSeries();
|
||||
lineSeries1.Title = "LineSeries 1";
|
||||
lineSeries1.ToolTip = "This is a tooltip for a LineSeries 1";
|
||||
lineSeries1.Color = OxyColors.SkyBlue;
|
||||
lineSeries1.StrokeThickness = 3;
|
||||
lineSeries1.LineStyle = LineStyle.Dash;
|
||||
lineSeries1.MarkerType = MarkerType.Circle;
|
||||
lineSeries1.MarkerSize = 5;
|
||||
lineSeries1.MarkerStroke = OxyColors.White;
|
||||
lineSeries1.MarkerFill = OxyColors.SkyBlue;
|
||||
lineSeries1.MarkerStrokeThickness = 1.5;
|
||||
model.Series.Add(lineSeries1);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Two LineSeries")]
|
||||
public static PlotModel TwoLineSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "Two LineSeries" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var lineSeries1 = CreateExampleLineSeries();
|
||||
lineSeries1.Title = "LineSeries 1";
|
||||
model.Series.Add(lineSeries1);
|
||||
|
||||
var lineSeries2 = CreateExampleLineSeries(41);
|
||||
lineSeries2.Title = "LineSeries 2";
|
||||
model.Series.Add(lineSeries2);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Visibility")]
|
||||
public static PlotModel IsVisibleFalse()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with IsVisible = false", Subtitle = "Click to change the IsVisible property for LineSeries 2" };
|
||||
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0, Maximum = 50 });
|
||||
|
||||
var s1 = CreateExampleLineSeries(38);
|
||||
s1.Title = "LineSeries 1";
|
||||
model.Series.Add(s1);
|
||||
|
||||
var s2 = CreateExampleLineSeries(39);
|
||||
s2.Title = "LineSeries 2";
|
||||
s2.IsVisible = false;
|
||||
model.Series.Add(s2);
|
||||
|
||||
// handle mouse clicks to change visibility
|
||||
model.MouseDown += (s, e) => { s2.IsVisible = !s2.IsVisible; model.InvalidatePlot(true); };
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Custom TrackerFormatString")]
|
||||
public static PlotModel TrackerFormatString()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with custom TrackerFormatString", Subtitle = "TrackerFormatString = \"X={2:0.0} Y={4:0.0}\"" };
|
||||
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
|
||||
var lineSeries1 = CreateExampleLineSeries();
|
||||
lineSeries1.TrackerFormatString = "X={2:0.0} Y={4:0.0}";
|
||||
model.Series.Add(lineSeries1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Custom markers")]
|
||||
public static PlotModel CustomMarkers()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with custom markers" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 30
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
const int N = 6;
|
||||
var customMarkerOutline = new ScreenPoint[N];
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
double th = Math.PI * ((4.0 * i / (N - 1)) - 0.5);
|
||||
const double R = 1;
|
||||
customMarkerOutline[i] = new ScreenPoint(Math.Cos(th) * R, Math.Sin(th) * R);
|
||||
}
|
||||
|
||||
var s1 = CreateExampleLineSeries(39);
|
||||
s1.Title = "LineSeries 1";
|
||||
s1.MarkerType = MarkerType.Custom;
|
||||
s1.MarkerSize = 8;
|
||||
s1.MarkerOutline = customMarkerOutline;
|
||||
|
||||
model.Series.Add(s1);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Marker types")]
|
||||
public static PlotModel MarkerTypes()
|
||||
{
|
||||
var pm = CreateModel("LineSeries with different MarkerType", (int)MarkerType.Custom);
|
||||
|
||||
var l = new Legend
|
||||
{
|
||||
LegendBackground = OxyColor.FromAColor(220, OxyColors.White),
|
||||
LegendBorder = OxyColors.Black,
|
||||
LegendBorderThickness = 1.0
|
||||
};
|
||||
|
||||
pm.Legends.Add(l);
|
||||
|
||||
int i = 0;
|
||||
foreach (var ls in pm.Series.Cast<LineSeries>())
|
||||
{
|
||||
ls.Color = OxyColors.Red;
|
||||
ls.MarkerStroke = OxyColors.Black;
|
||||
ls.MarkerFill = OxyColors.Green;
|
||||
ls.MarkerType = (MarkerType)i++;
|
||||
ls.Title = ls.MarkerType.ToString();
|
||||
}
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
[Example("Labels")]
|
||||
public static PlotModel Labels()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with labels", Subtitle = "Use the 'LabelFormatString' property" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.1 }); // increase the top padding to make sure the labels are visible
|
||||
var s1 = CreateExampleLineSeries();
|
||||
s1.LabelFormatString = "{1}";
|
||||
s1.MarkerType = MarkerType.Circle;
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("LineStyle")]
|
||||
public static PlotModel LineStyles()
|
||||
{
|
||||
var pm = CreateModel("LineSeries with LineStyle", (int)LineStyle.None);
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside,
|
||||
LegendSymbolLength = 50
|
||||
};
|
||||
|
||||
pm.Legends.Add(l);
|
||||
|
||||
int i = 0;
|
||||
foreach (var lineSeries in pm.Series.Cast<LineSeries>())
|
||||
{
|
||||
lineSeries.Color = OxyColors.Red;
|
||||
lineSeries.LineStyle = (LineStyle)i++;
|
||||
lineSeries.Title = lineSeries.LineStyle.ToString();
|
||||
}
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
[Example("Interpolation")]
|
||||
public static PlotModel Smooth()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with interpolation", Subtitle = "InterpolationAlgorithm = CanonicalSpline" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
var s1 = CreateExampleLineSeries();
|
||||
s1.MarkerType = MarkerType.Circle;
|
||||
s1.InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline;
|
||||
model.Series.Add(s1);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("LineLegendPosition")]
|
||||
public static PlotModel CustomLineLegendPosition()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with LineLegendPosition" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0.05, MaximumPadding = 0.05 });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0.05, MaximumPadding = 0.05 });
|
||||
var s1 = CreateExampleLineSeries();
|
||||
s1.Title = "Start";
|
||||
s1.MarkerType = MarkerType.Circle;
|
||||
s1.LineLegendPosition = LineLegendPosition.Start;
|
||||
model.Series.Add(s1);
|
||||
|
||||
var s2 = CreateExampleLineSeries(41);
|
||||
s2.Title = "End";
|
||||
s2.MarkerType = MarkerType.Circle;
|
||||
s2.LineLegendPosition = LineLegendPosition.End;
|
||||
model.Series.Add(s2);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("LineLegendPosition (reversed X Axis)")]
|
||||
public static PlotModel CustomLineLegendPositionReversed()
|
||||
{
|
||||
return CustomLineLegendPosition().ReverseXAxis();
|
||||
}
|
||||
|
||||
[Example("Broken lines")]
|
||||
public static PlotModel BrokenLine()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with broken lines" };
|
||||
|
||||
var s1 = CreateExampleLineSeries();
|
||||
s1.Points[3] = DataPoint.Undefined;
|
||||
s1.Points[7] = DataPoint.Undefined;
|
||||
s1.BrokenLineColor = OxyColors.Gray;
|
||||
s1.BrokenLineThickness = 0.5;
|
||||
s1.BrokenLineStyle = LineStyle.Solid;
|
||||
model.Series.Add(s1);
|
||||
|
||||
var s2 = CreateExampleLineSeries(49);
|
||||
s2.Points[3] = DataPoint.Undefined;
|
||||
s2.Points[7] = DataPoint.Undefined;
|
||||
s2.BrokenLineColor = OxyColors.Automatic;
|
||||
s2.BrokenLineThickness = 1;
|
||||
s2.BrokenLineStyle = LineStyle.Dot;
|
||||
model.Series.Add(s2);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Without Decimator")]
|
||||
public static PlotModel WithoutDecimator()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries without Decimator" };
|
||||
var s1 = CreateSeriesSuitableForDecimation();
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("With X Decimator")]
|
||||
public static PlotModel WithXDecimator()
|
||||
{
|
||||
var model = new PlotModel { Title = "LineSeries with X Decimator" };
|
||||
var s1 = CreateSeriesSuitableForDecimation();
|
||||
s1.Decimator = Decimator.Decimate;
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Canonical spline interpolation")]
|
||||
public static PlotModel CanonicalSplineInterpolation()
|
||||
{
|
||||
var result = CreateRandomPoints();
|
||||
|
||||
var plotModel = new PlotModel
|
||||
{
|
||||
Title = "Canonical spline interpolation",
|
||||
Series =
|
||||
{
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "Default (0.5)",
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerFill = OxyColors.Black
|
||||
},
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "0.1",
|
||||
InterpolationAlgorithm = new CanonicalSpline(0.1)
|
||||
},
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "1.0",
|
||||
InterpolationAlgorithm = new CanonicalSpline(1)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return plotModel;
|
||||
}
|
||||
|
||||
[Example("Catmull-Rom interpolation")]
|
||||
public static PlotModel CatmullRomInterpolation()
|
||||
{
|
||||
var result = CreateRandomPoints();
|
||||
|
||||
var plotModel = new PlotModel
|
||||
{
|
||||
Title = "Catmull-Rom interpolation",
|
||||
Series =
|
||||
{
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "Standard",
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.CatmullRomSpline,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerFill = OxyColors.Black
|
||||
},
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "Chordal",
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.ChordalCatmullRomSpline
|
||||
},
|
||||
new LineSeries
|
||||
{
|
||||
ItemsSource = result,
|
||||
Title = "Uniform",
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.UniformCatmullRomSpline
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return plotModel;
|
||||
}
|
||||
|
||||
[Example("Marker color options")]
|
||||
public static PlotModel MarkerColorOptions()
|
||||
{
|
||||
var result = CreateRandomPoints();
|
||||
|
||||
var model = new PlotModel { Title = "Marker color options" };
|
||||
|
||||
// Dont specify line or marker color. Defaults will be used.
|
||||
var s1 = CreateExampleLineSeries(1);
|
||||
s1.MarkerType = MarkerType.Circle;
|
||||
model.Series.Add(s1);
|
||||
|
||||
// Specify line color but not marker color. Marker color should be the same as line color.
|
||||
var s2 = CreateExampleLineSeries(4);
|
||||
s2.MarkerType = MarkerType.Square;
|
||||
s2.Color = OxyColors.LightBlue;
|
||||
model.Series.Add(s2);
|
||||
|
||||
// Specify marker color but not line color. Default color should be used for line.
|
||||
var s3 = CreateExampleLineSeries(13);
|
||||
s3.MarkerType = MarkerType.Square;
|
||||
s3.MarkerFill = OxyColors.Black;
|
||||
model.Series.Add(s3);
|
||||
|
||||
// Specify line and marker color. Specified colors should be used.
|
||||
var s4 = CreateExampleLineSeries(5);
|
||||
s4.MarkerType = MarkerType.Square;
|
||||
s4.MarkerFill = OxyColors.OrangeRed;
|
||||
s4.Color = OxyColors.Orange;
|
||||
model.Series.Add(s4);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private static List<DataPoint> CreateRandomPoints(int numberOfPoints = 50)
|
||||
{
|
||||
var r = new Random(13);
|
||||
var result = new List<DataPoint>(numberOfPoints);
|
||||
for (int i = 0; i < numberOfPoints; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
{
|
||||
result.Add(new DataPoint(i, 0.0));
|
||||
}
|
||||
else if (i < 10)
|
||||
{
|
||||
result.Add(new DataPoint(i, 1.0));
|
||||
}
|
||||
else if (i < 12)
|
||||
{
|
||||
result.Add(new DataPoint(i, 0.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new DataPoint(i, r.NextDouble()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example line series.
|
||||
/// </summary>
|
||||
/// <returns>A line series containing random points.</returns>
|
||||
private static LineSeries CreateExampleLineSeries(int seed = 13)
|
||||
{
|
||||
var lineSeries1 = new LineSeries();
|
||||
var r = new Random(seed);
|
||||
var y = r.Next(10, 30);
|
||||
for (int x = 0; x <= 100; x += 10)
|
||||
{
|
||||
lineSeries1.Points.Add(new DataPoint(x, y));
|
||||
y += r.Next(-5, 5);
|
||||
}
|
||||
|
||||
return lineSeries1;
|
||||
}
|
||||
|
||||
private static PlotModel CreateModel(string title, int n = 20)
|
||||
{
|
||||
var model = new PlotModel { Title = title };
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
var s = new LineSeries { Title = "Series " + i };
|
||||
model.Series.Add(s);
|
||||
for (double x = 0; x < 2 * Math.PI; x += 0.1)
|
||||
{
|
||||
s.Points.Add(new DataPoint(x, (Math.Sin(x * i) / (i + 1)) + i));
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private static LineSeries CreateSeriesSuitableForDecimation()
|
||||
{
|
||||
var s1 = new LineSeries();
|
||||
|
||||
int n = 20000;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint((double)i / n, Math.Sin(i)));
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
private static OxyPlot.Series.Series CreateRandomLineSeries(int n, string title, MarkerType markerType)
|
||||
{
|
||||
var s1 = new LineSeries { Title = title, MarkerType = markerType, MarkerStroke = OxyColors.Black, MarkerStrokeThickness = 1.0 };
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
x += 2 + Randomizer.NextDouble() * 10;
|
||||
y += 1 + Randomizer.NextDouble();
|
||||
var p = new DataPoint(x, y);
|
||||
s1.Points.Add(p);
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
}
|
||||
}
|
||||
119
Source/Examples/ExampleLibrary/Series/LinearBarSeriesExamples.cs
Normal file
119
Source/Examples/ExampleLibrary/Series/LinearBarSeriesExamples.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("LinearBarSeries"), Tags("Series")]
|
||||
public class LinearBarSeriesExamples
|
||||
{
|
||||
//private static readonly Random Randomizer = new Random(13);
|
||||
|
||||
[Example("Default style")]
|
||||
[DocumentationExample("Series/LinearBarSeries")]
|
||||
public static PlotModel DefaultStyle()
|
||||
{
|
||||
var model = new PlotModel { Title = "LinearBarSeries with default style" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var linearBarSeries = CreateExampleLinearBarSeries();
|
||||
linearBarSeries.Title = "LinearBarSeries";
|
||||
model.Series.Add(linearBarSeries);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("With stroke")]
|
||||
public static PlotModel WithStroke()
|
||||
{
|
||||
var model = new PlotModel { Title = "LinearBarSeries with stroke" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
var linearBarSeries = CreateExampleLinearBarSeries();
|
||||
linearBarSeries.Title = "LinearBarSeries";
|
||||
linearBarSeries.FillColor = OxyColor.Parse("#454CAF50");
|
||||
linearBarSeries.StrokeColor = OxyColor.Parse("#4CAF50");
|
||||
linearBarSeries.StrokeThickness = 1;
|
||||
model.Series.Add(linearBarSeries);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("With negative colors")]
|
||||
public static PlotModel WithNegativeColors()
|
||||
{
|
||||
return CreateWithNegativeColors();
|
||||
}
|
||||
|
||||
[Example("With negative colors (logaritmic)")]
|
||||
public static PlotModel WithNegativeColorsLogarithmic()
|
||||
{
|
||||
return CreateWithNegativeColors(logarithmic: true);
|
||||
}
|
||||
|
||||
[Example("With BaseValue")]
|
||||
public static PlotModel WithBaseValue()
|
||||
{
|
||||
return CreateWithNegativeColors(baseValue: 50);
|
||||
}
|
||||
|
||||
[Example("With BaseValue (Logarithmic)")]
|
||||
public static PlotModel WithBaseValueLogarithmic()
|
||||
{
|
||||
return CreateWithNegativeColors(logarithmic: true, baseValue: 50);
|
||||
}
|
||||
|
||||
public static PlotModel CreateWithNegativeColors(bool logarithmic = false, double baseValue = 0)
|
||||
{
|
||||
var model = new PlotModel { Title = logarithmic ? "LinearBarSeries with stroke (logarithmic)" : "LinearBarSeries with stroke" };
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
|
||||
model.Axes.Add(logarithmic ? (Axis)new LogarithmicAxis { Position = AxisPosition.Left } : new LinearAxis { Position = AxisPosition.Left });
|
||||
var linearBarSeries = CreateExampleLinearBarSeriesWithNegativeValues();
|
||||
linearBarSeries.Title = "LinearBarSeries";
|
||||
linearBarSeries.FillColor = OxyColor.Parse("#454CAF50");
|
||||
linearBarSeries.StrokeColor = OxyColor.Parse("#4CAF50");
|
||||
linearBarSeries.NegativeFillColor = OxyColor.Parse("#45BF360C");
|
||||
linearBarSeries.NegativeStrokeColor = OxyColor.Parse("#BF360C");
|
||||
linearBarSeries.StrokeThickness = 1;
|
||||
linearBarSeries.BaseValue = baseValue;
|
||||
model.Series.Add(linearBarSeries);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example linear bar series.
|
||||
/// </summary>
|
||||
/// <returns>A linear bar series containing random points.</returns>
|
||||
private static LinearBarSeries CreateExampleLinearBarSeries()
|
||||
{
|
||||
var linearBarSeries = new LinearBarSeries();
|
||||
var r = new Random(31);
|
||||
var y = r.Next(10, 30);
|
||||
for (int x = 0; x <= 50; x++)
|
||||
{
|
||||
linearBarSeries.Points.Add(new DataPoint(x, y));
|
||||
y += r.Next(-5, 5);
|
||||
}
|
||||
return linearBarSeries;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example linear bar series with negative values.
|
||||
/// </summary>
|
||||
/// <returns>A linear bar series containing random points.</returns>
|
||||
private static LinearBarSeries CreateExampleLinearBarSeriesWithNegativeValues()
|
||||
{
|
||||
var linearBarSeries = new LinearBarSeries();
|
||||
var r = new Random(31);
|
||||
for (int x = 0; x <= 50; x++)
|
||||
{
|
||||
var y = -200 + r.Next(1000);
|
||||
linearBarSeries.Points.Add(new DataPoint(x, y));
|
||||
}
|
||||
return linearBarSeries;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Source/Examples/ExampleLibrary/Series/PieSeriesExamples.cs
Normal file
55
Source/Examples/ExampleLibrary/Series/PieSeriesExamples.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="PieSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("PieSeries"), Tags("Series")]
|
||||
public static class PieSeriesExamples
|
||||
{
|
||||
[Example("PieSeries")]
|
||||
[DocumentationExample("Series/PieSeries")]
|
||||
public static PlotModel PieSeries()
|
||||
{
|
||||
return CreateExample();
|
||||
}
|
||||
|
||||
[Example("PieSeries with inside label color")]
|
||||
public static PlotModel InsideLabelColor()
|
||||
{
|
||||
var model = CreateExample();
|
||||
var series = (PieSeries)model.Series[0];
|
||||
series.InsideLabelColor = OxyColors.White;
|
||||
return model;
|
||||
}
|
||||
|
||||
private static PlotModel CreateExample()
|
||||
{
|
||||
var model = new PlotModel { Title = "World population by continent" };
|
||||
|
||||
var ps = new PieSeries
|
||||
{
|
||||
StrokeThickness = 2.0,
|
||||
InsideLabelPosition = 0.8,
|
||||
AngleSpan = 360,
|
||||
StartAngle = 0
|
||||
};
|
||||
|
||||
// http://www.nationsonline.org/oneworld/world_population.htm
|
||||
// http://en.wikipedia.org/wiki/Continent
|
||||
ps.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = true });
|
||||
ps.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true });
|
||||
ps.Slices.Add(new PieSlice("Asia", 4157));
|
||||
ps.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true });
|
||||
ps.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true });
|
||||
|
||||
model.Series.Add(ps);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="RectangleBarSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("RectangleBarSeries"), Tags("Series")]
|
||||
public static class RectangleBarSeriesExamples
|
||||
{
|
||||
[Example("RectangleBarSeries")]
|
||||
[DocumentationExample("Series/RectangleBarSeries")]
|
||||
public static PlotModel RectangleBarSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "RectangleBarSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
var s1 = new RectangleBarSeries { Title = "RectangleBarSeries 1" };
|
||||
s1.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = 1, Y1 = 4 });
|
||||
s1.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = 6, Y1 = 7 });
|
||||
model.Series.Add(s1);
|
||||
|
||||
var s2 = new RectangleBarSeries { Title = "RectangleBarSeries 2" };
|
||||
s2.Items.Add(new RectangleBarItem { X0 = 2, X1 = 8, Y0 = -4, Y1 = -1 });
|
||||
s2.Items.Add(new RectangleBarItem { X0 = 6, X1 = 12, Y0 = -7, Y1 = -6 });
|
||||
model.Series.Add(s2);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("RectangleSeries"), Tags("Series")]
|
||||
public static class RectangleSeriesExamples
|
||||
{
|
||||
[Example("RectangleSeries")]
|
||||
[DocumentationExample("Series/RectangleSeries")]
|
||||
public static PlotModel FromItems()
|
||||
{
|
||||
const int NumberOfItems = 10;
|
||||
var model = new PlotModel { Title = "RectangleSeries" };
|
||||
|
||||
// the RectangleSeries requires a color axis
|
||||
model.Axes.Add(new LinearColorAxis
|
||||
{
|
||||
Position = AxisPosition.Right,
|
||||
Palette = OxyPalettes.Jet(100)
|
||||
});
|
||||
|
||||
// create the series and add some rectangles with values
|
||||
var s = new RectangleSeries() { LabelFontSize = 12 };
|
||||
for (int i = NumberOfItems - 1; i >= 0; i--)
|
||||
{
|
||||
s.Items.Add(new RectangleItem(-i * 0.5, i * 0.5, i * i, i * (i + 3), i));
|
||||
}
|
||||
|
||||
model.Series.Add(s);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("RectangleSeries from ItemsSource and Mapping")]
|
||||
public static PlotModel FromItemsSource()
|
||||
{
|
||||
const int NumberOfItems = 10;
|
||||
var model = new PlotModel { Title = "RectangleSeries" };
|
||||
|
||||
// the RectangleSeries requires a color axis
|
||||
model.Axes.Add(new LinearColorAxis
|
||||
{
|
||||
Position = AxisPosition.Right,
|
||||
Palette = OxyPalettes.Jet(100)
|
||||
});
|
||||
|
||||
// create the data
|
||||
var items = new List<MyItem>();
|
||||
for (int i = 0; i < NumberOfItems; i++)
|
||||
{
|
||||
items.Add(new MyItem { X = i, Value = i });
|
||||
}
|
||||
|
||||
model.Series.Add(new RectangleSeries
|
||||
{
|
||||
ItemsSource = items,
|
||||
Mapping = x =>
|
||||
{
|
||||
var r = (MyItem)x;
|
||||
return new RectangleItem(r.X, r.X * 2, r.X, r.X * 2, r.Value);
|
||||
}
|
||||
});
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public class MyItem
|
||||
{
|
||||
public double X { get; set; }
|
||||
public double Value { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ScatterErrorSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Creates an example model with the specified number of points.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("ScatterErrorSeries"), Tags("Series")]
|
||||
public class ScatterErrorSeriesExamples
|
||||
{
|
||||
[Example("Random points and errors (n=20)")]
|
||||
[DocumentationExample("Series/ScatterErrorSeries")]
|
||||
public static PlotModel RandomPointsAndError20()
|
||||
{
|
||||
return RandomPointsAndError(20);
|
||||
}
|
||||
|
||||
[Example("Random points and errors (n=2000)")]
|
||||
public static PlotModel RandomPointsAndError2000()
|
||||
{
|
||||
return RandomPointsAndError(2000);
|
||||
}
|
||||
|
||||
[Example("Definining points by ItemsSource and Mapping")]
|
||||
public static PlotModel ItemsSourceMapping()
|
||||
{
|
||||
const int N = 20;
|
||||
var model = new PlotModel { Title = "ScatterErrorSeries, points defined by ItemsSource and Mapping", Subtitle = string.Format("Random data (n={0})", N) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
model.Series.Add(new ScatterErrorSeries
|
||||
{
|
||||
Title = "Measurements",
|
||||
ItemsSource = CreateExamplePoints(N).ToArray(),
|
||||
Mapping =
|
||||
obj =>
|
||||
{
|
||||
var p = (ExamplePoint)obj;
|
||||
return new ScatterErrorPoint(p.V1, p.V2, p.E1, p.E2);
|
||||
}
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Defining points by ItemsSource (List)")]
|
||||
public static PlotModel ItemsSourceList()
|
||||
{
|
||||
const int N = 20;
|
||||
var model = new PlotModel { Title = "ScatterErrorSeries, points defined by ItemsSource (List)", Subtitle = string.Format("Random data (n={0})", N) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
model.Series.Add(new ScatterErrorSeries { Title = "Measurements", ItemsSource = CreateScatterErrorPoints(N).ToList() });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Defining points by ItemsSource (IEnumerable)")]
|
||||
public static PlotModel ItemsSourceEnumerable()
|
||||
{
|
||||
const int N = 20;
|
||||
var model = new PlotModel { Title = "ScatterErrorSeries, points defined by ItemsSource (IEnumerable)", Subtitle = string.Format("Random data (n={0})", N) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
model.Series.Add(new ScatterErrorSeries { Title = "Measurements", ItemsSource = CreateScatterErrorPoints(N).ToArray() });
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Definining points by ItemsSource and reflection")]
|
||||
public static PlotModel ItemsSourceReflection()
|
||||
{
|
||||
const int N = 20;
|
||||
var model = new PlotModel { Title = "ScatterErrorSeries, points defined by ItemsSource (reflection)", Subtitle = string.Format("Random data (n={0})", N) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
model.Series.Add(new ScatterErrorSeries
|
||||
{
|
||||
Title = "Measurements",
|
||||
ItemsSource = CreateExamplePoints(N).ToArray(),
|
||||
DataFieldX = "V1",
|
||||
DataFieldY = "V2",
|
||||
DataFieldErrorX = "E1",
|
||||
DataFieldErrorY = "E2"
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example model with the specified number of points.
|
||||
/// </summary>
|
||||
/// <param name="n">The n.</param>
|
||||
/// <returns>A plot model.</returns>
|
||||
private static PlotModel RandomPointsAndError(int n)
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterErrorSeries", Subtitle = string.Format("Random data (n={0})", n) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
var s1 = new ScatterErrorSeries { Title = "Measurements" };
|
||||
s1.Points.AddRange(CreateScatterErrorPoints(n));
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates random example data.
|
||||
/// </summary>
|
||||
/// <param name="n">The number of points to generate.</param>
|
||||
/// <returns>A sequence of points.</returns>
|
||||
private static IEnumerable<ScatterErrorPoint> CreateScatterErrorPoints(int n)
|
||||
{
|
||||
var random = new Random(27);
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
x += 2 + random.NextDouble();
|
||||
y += 1 + random.NextDouble();
|
||||
|
||||
yield return new ScatterErrorPoint(x, y, random.NextDouble(), random.NextDouble());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates random example data.
|
||||
/// </summary>
|
||||
/// <param name="n">The number of points to generate.</param>
|
||||
/// <returns>A sequence of points.</returns>
|
||||
private static IEnumerable<ExamplePoint> CreateExamplePoints(int n)
|
||||
{
|
||||
var random = new Random(27);
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
x += 2 + random.NextDouble();
|
||||
y += 1 + random.NextDouble();
|
||||
|
||||
yield return new ExamplePoint { V1 = x, V2 = y, E1 = random.NextDouble(), E2 = random.NextDouble() };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a point with errors.
|
||||
/// </summary>
|
||||
public class ExamplePoint
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the first value.
|
||||
/// </summary>
|
||||
public double V1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second value.
|
||||
/// </summary>
|
||||
public double V2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the first error.
|
||||
/// </summary>
|
||||
public double E1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the second error.
|
||||
/// </summary>
|
||||
public double E2 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
623
Source/Examples/ExampleLibrary/Series/ScatterSeriesExamples.cs
Normal file
623
Source/Examples/ExampleLibrary/Series/ScatterSeriesExamples.cs
Normal file
@@ -0,0 +1,623 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ScatterSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Calculates the Least squares fit of a list of DataPoints.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Annotations;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("ScatterSeries"), Tags("Series")]
|
||||
public class ScatterSeriesExamples
|
||||
{
|
||||
[Example("Correlated points")]
|
||||
[DocumentationExample("Series/ScatterSeries")]
|
||||
public static PlotModel CorrelatedScatter()
|
||||
{
|
||||
return CreateCorrelatedScatter(1000);
|
||||
}
|
||||
|
||||
[Example("Random points")]
|
||||
public static PlotModel RandomScatter()
|
||||
{
|
||||
return RandomScatter(32768, 0);
|
||||
}
|
||||
|
||||
[Example("Random points (BinSize=2)")]
|
||||
public static PlotModel RandomScatter2()
|
||||
{
|
||||
return RandomScatter(32768, 2);
|
||||
}
|
||||
|
||||
[Example("Random points (BinSize=4)")]
|
||||
public static PlotModel RandomScatter4()
|
||||
{
|
||||
return RandomScatter(32768, 4);
|
||||
}
|
||||
|
||||
[Example("Random points (BinSize=6)")]
|
||||
public static PlotModel RandomScatter6()
|
||||
{
|
||||
return RandomScatter(32768, 6);
|
||||
}
|
||||
|
||||
[Example("Random points (BinSize=8)")]
|
||||
public static PlotModel RandomScatter8()
|
||||
{
|
||||
return RandomScatter(32768, 8);
|
||||
}
|
||||
|
||||
[Example("Random points (BinSize=10)")]
|
||||
public static PlotModel RandomScatter10()
|
||||
{
|
||||
return RandomScatter(32768, 10);
|
||||
}
|
||||
|
||||
[Example("Two ScatterSeries")]
|
||||
public static PlotModel TwoScatterSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "Two ScatterSeries (with and without values)", Subtitle = "With values (squares), without values (triangles)" };
|
||||
var colorAxis = new LinearColorAxis { Position = AxisPosition.Right, Key = "ColorAxis", Palette = OxyPalettes.Jet(30), Minimum = -1, Maximum = 1 };
|
||||
model.Axes.Add(colorAxis);
|
||||
model.Series.Add(CreateRandomScatterSeries(50, MarkerType.Triangle, false, false, null));
|
||||
model.Series.Add(CreateRandomScatterSeries(50, MarkerType.Square, false, true, colorAxis));
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("LabelFormatString")]
|
||||
public static PlotModel LabelFormatString()
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterSeries with LabelFormatString" };
|
||||
var s = CreateRandomScatterSeries(50, MarkerType.Square, false, false, null);
|
||||
s.LabelFormatString = "{1:0.###}";
|
||||
model.Series.Add(s);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette, MarkerType markerType, AxisPosition colorAxisPosition, OxyColor highColor, OxyColor lowColor)
|
||||
{
|
||||
var model = new PlotModel { Title = string.Format("ScatterSeries (n={0})", n), Background = OxyColors.LightGray };
|
||||
var colorAxis = new LinearColorAxis { Position = colorAxisPosition, Palette = palette, Minimum = -1, Maximum = 1, HighColor = highColor, LowColor = lowColor };
|
||||
model.Axes.Add(colorAxis);
|
||||
model.Series.Add(CreateRandomScatterSeries(n, markerType, false, true, colorAxis));
|
||||
return model;
|
||||
}
|
||||
|
||||
private static ScatterSeries CreateRandomScatterSeries(int n, MarkerType markerType, bool setSize, bool setValue, LinearColorAxis colorAxis)
|
||||
{
|
||||
var s1 = new ScatterSeries
|
||||
{
|
||||
MarkerType = markerType,
|
||||
MarkerSize = 6,
|
||||
ColorAxisKey = colorAxis != null ? colorAxis.Key : null
|
||||
};
|
||||
var random = new Random(13);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
var p = new ScatterPoint((random.NextDouble() * 2.2) - 1.1, random.NextDouble());
|
||||
if (setSize)
|
||||
{
|
||||
p.Size = (random.NextDouble() * 5) + 5;
|
||||
}
|
||||
|
||||
if (setValue)
|
||||
{
|
||||
p.Value = (random.NextDouble() * 2.2) - 1.1;
|
||||
}
|
||||
|
||||
s1.Points.Add(p);
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
[Example("Random points with random size")]
|
||||
public static PlotModel RandomSize()
|
||||
{
|
||||
return RandomSize(1000, 8);
|
||||
}
|
||||
|
||||
public static PlotModel RandomSize(int n, int binsize)
|
||||
{
|
||||
var model = new PlotModel { Title = string.Format("ScatterSeries with random MarkerSize (n={0})", n), Subtitle = "BinSize = " + binsize };
|
||||
|
||||
var s1 = new ScatterSeries { Title = "Series 1", MarkerStrokeThickness = 0, BinSize = binsize };
|
||||
var random = new Random(13);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
s1.Points.Add(new ScatterPoint(random.NextDouble(), random.NextDouble(), 4 + (10 * random.NextDouble())));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Random points with least squares fit")]
|
||||
public static PlotModel RandomWithFit()
|
||||
{
|
||||
const int n = 20;
|
||||
var model = new PlotModel { Title = string.Format("Random data (n={0})", n) };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPosition = LegendPosition.LeftTop
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new ScatterSeries { Title = "Measurements" };
|
||||
var random = new Random(7);
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
x += 2 + (random.NextDouble() * 10);
|
||||
y += 1 + random.NextDouble();
|
||||
var p = new ScatterPoint(x, y);
|
||||
s1.Points.Add(p);
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
double a, b;
|
||||
LeastSquaresFit(s1.Points, out a, out b);
|
||||
model.Annotations.Add(new LineAnnotation { Slope = a, Intercept = b, Text = "Least squares fit" });
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Least squares fit of a list of DataPoints.
|
||||
/// </summary>
|
||||
/// <param name="points">The points.</param>
|
||||
/// <param name="a">The slope.</param>
|
||||
/// <param name="b">The intercept.</param>
|
||||
public static void LeastSquaresFit(IEnumerable<ScatterPoint> points, out double a, out double b)
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Least_squares
|
||||
// http://mathworld.wolfram.com/LeastSquaresFitting.html
|
||||
// http://web.cecs.pdx.edu/~gerry/nmm/course/slides/ch09Slides4up.pdf
|
||||
|
||||
double Sx = 0;
|
||||
double Sy = 0;
|
||||
double Sxy = 0;
|
||||
double Sxx = 0;
|
||||
int m = 0;
|
||||
foreach (var p in points)
|
||||
{
|
||||
Sx += p.X;
|
||||
Sy += p.Y;
|
||||
Sxy += p.X * p.Y;
|
||||
Sxx += p.X * p.X;
|
||||
m++;
|
||||
}
|
||||
|
||||
double d = Sx * Sx - m * Sxx;
|
||||
a = 1 / d * (Sx * Sy - m * Sxy);
|
||||
b = 1 / d * (Sx * Sxy - Sxx * Sy);
|
||||
}
|
||||
|
||||
[Example("Marker types")]
|
||||
public static PlotModel MarkerTypes()
|
||||
{
|
||||
var model = new PlotModel { Title = "Marker types" };
|
||||
var r = new Random(12345);
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Circle", MarkerType.Circle));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Cross", MarkerType.Cross));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Diamond", MarkerType.Diamond));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Plus", MarkerType.Plus));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Square", MarkerType.Square));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Star", MarkerType.Star));
|
||||
model.Series.Add(CreateRandomScatterSeries(r, 10, "Triangle", MarkerType.Triangle));
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries.Points")]
|
||||
public static PlotModel DataPoints()
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterSeries (n=1000)", Subtitle = "The scatter points are added to the Points collection." };
|
||||
var series = new ScatterSeries();
|
||||
series.Points.AddRange(CreateRandomScatterPoints(1000));
|
||||
model.Series.Add(series);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries.ItemsSource")]
|
||||
public static PlotModel FromItemsSource()
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterSeries (n=1000)", Subtitle = "The scatter points are defined in the ItemsSource property." };
|
||||
model.Series.Add(new ScatterSeries
|
||||
{
|
||||
ItemsSource = CreateRandomScatterPoints(1000),
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries.ItemsSource + Mapping")]
|
||||
public static PlotModel FromMapping()
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterSeries (n=1000)", Subtitle = "The scatter points are defined by a mapping from the ItemsSource." };
|
||||
model.Series.Add(new ScatterSeries
|
||||
{
|
||||
ItemsSource = CreateRandomDataPoints(1000),
|
||||
Mapping = item => new ScatterPoint(((DataPoint)item).X, ((DataPoint)item).Y)
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries.ItemsSource + reflection")]
|
||||
public static PlotModel FromItemsSourceReflection()
|
||||
{
|
||||
var model = new PlotModel { Title = "ScatterSeries (n=1000)", Subtitle = "The scatter points are defined by reflection from the ItemsSource." };
|
||||
model.Series.Add(new ScatterSeries
|
||||
{
|
||||
ItemsSource = CreateRandomDataPoints(1000),
|
||||
DataFieldX = "X",
|
||||
DataFieldY = "Y"
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Rainbow(16)")]
|
||||
public static PlotModel ColorMapRainbow16()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Rainbow(16), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Hue(30) Star")]
|
||||
public static PlotModel ColorMapHue30()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Hue(30), MarkerType.Star, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Hot(64)")]
|
||||
public static PlotModel ColorMapHot64()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Hot(64), MarkerType.Triangle, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Cool(32)")]
|
||||
public static PlotModel ColorMapCool32()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Cool(32), MarkerType.Circle, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Gray(32)")]
|
||||
public static PlotModel ColorMapGray32()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Gray(32), MarkerType.Diamond, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Jet(32)")]
|
||||
public static PlotModel ColorMapJet32()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Jet(32), MarkerType.Plus, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Hot with extreme colors")]
|
||||
public static PlotModel ColorMapHot64Extreme()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Hot(64), MarkerType.Square, AxisPosition.Right, OxyColors.Magenta, OxyColors.Green);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Hot (top legend)")]
|
||||
public static PlotModel ColorMapHot64ExtremeTopLegend()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Hot(64), MarkerType.Cross, AxisPosition.Top, OxyColors.Magenta, OxyColors.Green);
|
||||
}
|
||||
[Example("ScatterSeries with ColorAxis Hot(16) N=31000")]
|
||||
public static PlotModel ColorMapHot16Big()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(31000, OxyPalettes.Hot(16), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis BlueWhiteRed (3)")]
|
||||
public static PlotModel ColorMapBlueWhiteRed3()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.BlueWhiteRed(3), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis BlueWhiteRed (9)")]
|
||||
public static PlotModel ColorMapBlueWhiteRed9()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.BlueWhiteRed(9), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis BlueWhiteRed (256)")]
|
||||
public static PlotModel ColorMapBlueWhiteRed256()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.BlueWhiteRed(256), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis BlackWhiteRed (9)")]
|
||||
public static PlotModel ColorMapBlackWhiteRed9()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.BlackWhiteRed(9), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis BlackWhiteRed (9) top legend")]
|
||||
public static PlotModel ColorMapBlackWhiteRed9TopLegend()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.BlackWhiteRed(9), MarkerType.Square, AxisPosition.Top, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Viridis")]
|
||||
public static PlotModel ColorMapViridis()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Viridis(), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Plasma")]
|
||||
public static PlotModel ColorMapPlasma()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Plasma(), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Magma")]
|
||||
public static PlotModel ColorMapMagma()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Magma(), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Inferno")]
|
||||
public static PlotModel ColorMapInferno()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Inferno(), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with ColorAxis Cividis")]
|
||||
public static PlotModel ColorMapCividis()
|
||||
{
|
||||
return CreateRandomScatterSeriesWithColorAxisPlotModel(2500, OxyPalettes.Cividis(), MarkerType.Square, AxisPosition.Right, OxyColors.Undefined, OxyColors.Undefined);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with single-selected items")]
|
||||
public static PlotModel SingleSelectItems()
|
||||
{
|
||||
var model = RandomScatter(10, 8);
|
||||
model.Subtitle = "Click to select a point";
|
||||
|
||||
model.SelectionColor = OxyColors.Red;
|
||||
|
||||
var series = model.Series[0];
|
||||
|
||||
series.SelectionMode = SelectionMode.Single;
|
||||
|
||||
series.SelectItem(3);
|
||||
series.SelectItem(5);
|
||||
|
||||
series.MouseDown += (s, e) =>
|
||||
{
|
||||
var index = (int)e.HitTestResult.Index;
|
||||
series.SelectItem(index);
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = true;
|
||||
};
|
||||
model.MouseDown += (s, e) =>
|
||||
{
|
||||
series.ClearSelection();
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with multi-selected items")]
|
||||
public static PlotModel MultiSelectItems()
|
||||
{
|
||||
var model = RandomScatter(10, 8);
|
||||
model.Subtitle = "Click to toggle point selection";
|
||||
|
||||
model.SelectionColor = OxyColors.Red;
|
||||
|
||||
var series = model.Series[0];
|
||||
|
||||
series.SelectionMode = SelectionMode.Multiple;
|
||||
|
||||
series.SelectItem(3);
|
||||
series.SelectItem(5);
|
||||
|
||||
series.MouseDown += (s, e) =>
|
||||
{
|
||||
var index = (int)e.HitTestResult.Index;
|
||||
|
||||
// Toggle the selection state for this item
|
||||
if (series.IsItemSelected(index))
|
||||
{
|
||||
series.UnselectItem(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
series.SelectItem(index);
|
||||
}
|
||||
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
model.MouseDown += (s, e) =>
|
||||
{
|
||||
series.ClearSelection();
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with SelectionMode.All (no tracker)")]
|
||||
public static PlotModel AllSelected()
|
||||
{
|
||||
return AllSelected(false);
|
||||
}
|
||||
|
||||
[Example("ScatterSeries with SelectionMode.All (with tracker)")]
|
||||
public static PlotModel AllSelectedWithTracker()
|
||||
{
|
||||
return AllSelected(true);
|
||||
}
|
||||
|
||||
private static PlotModel AllSelected(bool showTracker)
|
||||
{
|
||||
var model = RandomScatter(10, 8);
|
||||
model.Subtitle = "Click to select all points";
|
||||
|
||||
model.SelectionColor = OxyColors.Red;
|
||||
|
||||
var series = model.Series[0];
|
||||
|
||||
series.SelectionMode = SelectionMode.All;
|
||||
|
||||
series.MouseDown += (s, e) =>
|
||||
{
|
||||
series.Select();
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = !showTracker;
|
||||
};
|
||||
|
||||
model.MouseDown += (s, e) =>
|
||||
{
|
||||
if (e.HitTestResult != null && showTracker)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
series.ClearSelection();
|
||||
model.InvalidatePlot(false);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("TrackerFormatString")]
|
||||
public static PlotModel TrackerFormatString()
|
||||
{
|
||||
var model = new PlotModel { Title = "TrackerFormatString" };
|
||||
|
||||
var s1 = new ScatterSeries { TrackerFormatString = "{Sum:0.0}", DataFieldX = "X", DataFieldY = "Y" };
|
||||
var myPoints = new List<MyPoint>
|
||||
{
|
||||
new MyPoint { X = 10, Y = 40 },
|
||||
new MyPoint { X = 40, Y = 20 },
|
||||
new MyPoint { X = 60, Y = 30 }
|
||||
};
|
||||
s1.ItemsSource = myPoints;
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
public struct MyPoint
|
||||
{
|
||||
public double X { get; set; }
|
||||
|
||||
public double Y { get; set; }
|
||||
|
||||
public double Sum
|
||||
{
|
||||
get
|
||||
{
|
||||
// calculated on request
|
||||
return this.X + this.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PlotModel RandomScatter(int n, int binSize)
|
||||
{
|
||||
var model = new PlotModel { Title = string.Format("ScatterSeries (n={0})", n), Subtitle = binSize > 0 ? "BinSize = " + binSize : "No 'binning'" };
|
||||
|
||||
var s1 = new ScatterSeries()
|
||||
{
|
||||
Title = "Series 1",
|
||||
MarkerType = MarkerType.Diamond,
|
||||
MarkerStrokeThickness = 0,
|
||||
BinSize = binSize
|
||||
};
|
||||
|
||||
var random = new Random(1);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
s1.Points.Add(new ScatterPoint(random.NextDouble(), random.NextDouble()));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static PlotModel CreateCorrelatedScatter(int n)
|
||||
{
|
||||
var model = new PlotModel { Title = string.Format("Correlated ScatterSeries (n={0})", n) };
|
||||
|
||||
var s1 = new ScatterSeries
|
||||
{
|
||||
Title = "Series 1",
|
||||
MarkerType = MarkerType.Diamond,
|
||||
MarkerStrokeThickness = 0,
|
||||
};
|
||||
|
||||
var random = new Random(1);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
var x = GetNormalDistributedValue(random);
|
||||
var y = 2 * x * x + GetNormalDistributedValue(random);
|
||||
s1.Points.Add(new ScatterPoint(x, y));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static ScatterSeries CreateRandomScatterSeries(Random r, int n, string title, MarkerType markerType)
|
||||
{
|
||||
var s1 = new ScatterSeries { Title = title, MarkerType = markerType, MarkerStroke = OxyColors.Black, MarkerStrokeThickness = 1.0 };
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double x = r.NextDouble() * 10;
|
||||
double y = r.NextDouble() * 10;
|
||||
var p = new ScatterPoint(x, y);
|
||||
s1.Points.Add(p);
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
private static double GetNormalDistributedValue(Random rnd)
|
||||
{
|
||||
var d1 = rnd.NextDouble();
|
||||
var d2 = rnd.NextDouble();
|
||||
return Math.Sqrt(-2.0 * Math.Log(d1)) * Math.Sin(2.0 * Math.PI * d2);
|
||||
}
|
||||
|
||||
private static List<DataPoint> CreateRandomDataPoints(int n)
|
||||
{
|
||||
return CreateRandomScatterPoints(n).Select(sp => new DataPoint(sp.X, sp.Y)).ToList();
|
||||
}
|
||||
|
||||
private static List<ScatterPoint> CreateRandomScatterPoints(int n)
|
||||
{
|
||||
var r = new Random(12345);
|
||||
|
||||
var points = new List<ScatterPoint>();
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double x = r.NextDouble() * 10;
|
||||
double y = r.NextDouble() * 10;
|
||||
var p = new ScatterPoint(x, y);
|
||||
points.Add(p);
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
}
|
||||
}
|
||||
230
Source/Examples/ExampleLibrary/Series/StairStepSeriesExamples.cs
Normal file
230
Source/Examples/ExampleLibrary/Series/StairStepSeriesExamples.cs
Normal file
@@ -0,0 +1,230 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="StairStepSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the <see cref="StairStepSeries" />.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="StairStepSeries" />.
|
||||
/// </summary>
|
||||
[Examples("StairStepSeries"), Tags("Series")]
|
||||
public static class StairStepSeriesExamples
|
||||
{
|
||||
[Example("StairStepSeries")]
|
||||
[DocumentationExample("Series/StairStepSeries")]
|
||||
public static PlotModel StairStepSeries()
|
||||
{
|
||||
return CreateExampleModel(new StairStepSeries());
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with labels")]
|
||||
public static PlotModel StairStepSeriesWithLabels()
|
||||
{
|
||||
return CreateExampleModel(new StairStepSeries { LabelFormatString = "{1:0.00}" });
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with markers")]
|
||||
public static PlotModel StairStepSeriesWithMarkers()
|
||||
{
|
||||
return CreateExampleModel(new StairStepSeries
|
||||
{
|
||||
Color = OxyColors.SkyBlue,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 6,
|
||||
MarkerStroke = OxyColors.White,
|
||||
MarkerFill = OxyColors.SkyBlue,
|
||||
MarkerStrokeThickness = 1.5
|
||||
});
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with thin vertical lines")]
|
||||
public static PlotModel StairStepSeriesThinVertical()
|
||||
{
|
||||
return CreateExampleModel(new StairStepSeries
|
||||
{
|
||||
StrokeThickness = 3,
|
||||
VerticalStrokeThickness = 0.4,
|
||||
MarkerType = MarkerType.None
|
||||
});
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with dashed vertical lines")]
|
||||
public static PlotModel StairStepSeriesDashedVertical()
|
||||
{
|
||||
return CreateExampleModel(new StairStepSeries
|
||||
{
|
||||
VerticalLineStyle = LineStyle.Dash,
|
||||
MarkerType = MarkerType.None
|
||||
});
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with invalid points")]
|
||||
public static PlotModel StairStepSeriesWithInvalidPoints()
|
||||
{
|
||||
var model = new PlotModel
|
||||
{
|
||||
Title = "StairStepSeries with invalid points",
|
||||
Subtitle = "Horizontal lines do not continue",
|
||||
};
|
||||
|
||||
PopulateInvalidPointExampleModel(model, x => DataPoint.Undefined);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with invalid Y")]
|
||||
public static PlotModel StairStepSeriesWithInvalidY()
|
||||
{
|
||||
var model = new PlotModel
|
||||
{
|
||||
Title = "StairStepSeries with invalid Y",
|
||||
Subtitle = "Horizontal lines continue until X of point with invalid Y",
|
||||
};
|
||||
|
||||
PopulateInvalidPointExampleModel(model, x => new DataPoint(x, double.NaN));
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("StairStepSeries with non-monotonic X")]
|
||||
public static PlotModel StairStepSeriesWithNonmonotonicX()
|
||||
{
|
||||
var model = new PlotModel
|
||||
{
|
||||
Title = "StairStepSeries with non-monotonic X",
|
||||
Subtitle = "Lines form a boxed I-beam",
|
||||
};
|
||||
|
||||
var iBeamSeries = new StairStepSeries
|
||||
{
|
||||
MarkerType = MarkerType.Circle,
|
||||
VerticalLineStyle = LineStyle.Dash,
|
||||
VerticalStrokeThickness = 4,
|
||||
};
|
||||
iBeamSeries.Points.Add(new DataPoint(1, 1));
|
||||
iBeamSeries.Points.Add(new DataPoint(3, 1));
|
||||
iBeamSeries.Points.Add(new DataPoint(2, 3));
|
||||
iBeamSeries.Points.Add(new DataPoint(1, 3));
|
||||
iBeamSeries.Points.Add(new DataPoint(3, 3));
|
||||
model.Series.Add(iBeamSeries);
|
||||
|
||||
var boxBRSeries = new StairStepSeries
|
||||
{
|
||||
MarkerType = MarkerType.Circle,
|
||||
VerticalLineStyle = LineStyle.Dash,
|
||||
VerticalStrokeThickness = 4,
|
||||
};
|
||||
boxBRSeries.Points.Add(new DataPoint(1, 0));
|
||||
boxBRSeries.Points.Add(new DataPoint(2, 0));
|
||||
boxBRSeries.Points.Add(new DataPoint(0, 0));
|
||||
boxBRSeries.Points.Add(new DataPoint(4, 0));
|
||||
boxBRSeries.Points.Add(new DataPoint(4, 4));
|
||||
model.Series.Add(boxBRSeries);
|
||||
|
||||
var boxTLSeries = new StairStepSeries
|
||||
{
|
||||
MarkerType = MarkerType.Circle,
|
||||
VerticalLineStyle = LineStyle.Dash,
|
||||
VerticalStrokeThickness = 4,
|
||||
};
|
||||
boxTLSeries.Points.Add(new DataPoint(3, 4));
|
||||
boxTLSeries.Points.Add(new DataPoint(2, 4));
|
||||
boxTLSeries.Points.Add(new DataPoint(4, 4));
|
||||
boxTLSeries.Points.Add(new DataPoint(0, 4));
|
||||
boxTLSeries.Points.Add(new DataPoint(0, 0));
|
||||
model.Series.Add(boxTLSeries);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example model and fills the specified series with points.
|
||||
/// </summary>
|
||||
/// <param name="series">The series.</param>
|
||||
/// <returns>A plot model.</returns>
|
||||
private static PlotModel CreateExampleModel(DataPointSeries series)
|
||||
{
|
||||
var model = new PlotModel { Title = "StairStepSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
series.Title = "sin(x)";
|
||||
for (double x = 0; x < Math.PI * 2; x += 0.5)
|
||||
{
|
||||
series.Points.Add(new DataPoint(x, Math.Sin(x)));
|
||||
}
|
||||
|
||||
model.Series.Add(series);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static void PopulateInvalidPointExampleModel(PlotModel model, Func<double, DataPoint> getInvalidPoint)
|
||||
{
|
||||
model.Legends.Add(new Legend()
|
||||
{
|
||||
LegendOrientation = LegendOrientation.Horizontal,
|
||||
LegendPlacement = LegendPlacement.Outside,
|
||||
LegendPosition = LegendPosition.BottomCenter,
|
||||
});
|
||||
|
||||
var series1 = new StairStepSeries
|
||||
{
|
||||
Title = "Invalid First Point",
|
||||
MarkerType = MarkerType.Circle,
|
||||
};
|
||||
series1.Points.Add(getInvalidPoint(0));
|
||||
series1.Points.Add(new DataPoint(1, 3.5));
|
||||
series1.Points.Add(new DataPoint(2, 4.0));
|
||||
series1.Points.Add(new DataPoint(3, 4.5));
|
||||
model.Series.Add(series1);
|
||||
|
||||
var series2 = new StairStepSeries
|
||||
{
|
||||
Title = "Invalid Second Point",
|
||||
MarkerType = MarkerType.Circle,
|
||||
};
|
||||
series2.Points.Add(new DataPoint(0, 2.0));
|
||||
series2.Points.Add(getInvalidPoint(1));
|
||||
series2.Points.Add(new DataPoint(2, 3.0));
|
||||
series2.Points.Add(new DataPoint(3, 3.5));
|
||||
model.Series.Add(series2);
|
||||
|
||||
var series3 = new StairStepSeries
|
||||
{
|
||||
Title = "Invalid Penultimate Point",
|
||||
MarkerType = MarkerType.Circle,
|
||||
};
|
||||
series3.Points.Add(new DataPoint(0, 1.0));
|
||||
series3.Points.Add(new DataPoint(1, 1.5));
|
||||
series3.Points.Add(getInvalidPoint(2));
|
||||
series3.Points.Add(new DataPoint(3, 2.5));
|
||||
model.Series.Add(series3);
|
||||
|
||||
var series4 = new StairStepSeries
|
||||
{
|
||||
Title = "Invalid Last Point",
|
||||
MarkerType = MarkerType.Circle,
|
||||
};
|
||||
series4.Points.Add(new DataPoint(0, 0.0));
|
||||
series4.Points.Add(new DataPoint(1, 0.5));
|
||||
series4.Points.Add(new DataPoint(2, 1.0));
|
||||
series4.Points.Add(getInvalidPoint(3));
|
||||
model.Series.Add(series4);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Source/Examples/ExampleLibrary/Series/StemSeriesExamples.cs
Normal file
62
Source/Examples/ExampleLibrary/Series/StemSeriesExamples.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="StemSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the <see cref="StemSeries" />.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="StemSeries" />.
|
||||
/// </summary>
|
||||
[Examples("StemSeries"), Tags("Series")]
|
||||
public static class StemSeriesExamples
|
||||
{
|
||||
[Example("StemSeries")]
|
||||
[DocumentationExample("Series/StemSeries")]
|
||||
public static PlotModel StemSeries()
|
||||
{
|
||||
return CreateExampleModel(new StemSeries
|
||||
{
|
||||
Color = OxyColors.SkyBlue,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 6,
|
||||
MarkerStroke = OxyColors.White,
|
||||
MarkerStrokeThickness = 1.5
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example model and fills the specified series with points.
|
||||
/// </summary>
|
||||
/// <param name="series">The series.</param>
|
||||
/// <returns>A plot model.</returns>
|
||||
private static PlotModel CreateExampleModel(DataPointSeries series)
|
||||
{
|
||||
var model = new PlotModel { Title = "StemSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
series.Title = "sin(x)";
|
||||
for (double x = 0; x < Math.PI * 2; x += 0.1)
|
||||
{
|
||||
series.Points.Add(new DataPoint(x, Math.Sin(x)));
|
||||
}
|
||||
|
||||
model.Series.Add(series);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ThreeColorLineSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the ThreeColorLineSeries.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary.Series
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="ThreeColorLineSeries" />.
|
||||
/// </summary>
|
||||
[Examples("ThreeColorLineSeries"), Tags("Series")]
|
||||
public class ThreeColorLineSeriesExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Temperatures")]
|
||||
[DocumentationExample("Series/ThreeColorLineSeries")]
|
||||
public static PlotModel ThreeColorLineSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "ThreeColorLineSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new ThreeColorLineSeries
|
||||
{
|
||||
Title = "Temperature at Eidesmoen, December 1986.",
|
||||
TrackerFormatString = "December {2:0}: {4:0.0} °C",
|
||||
MarkerSize = 4,
|
||||
MarkerStroke = OxyColors.Black,
|
||||
MarkerStrokeThickness = 1.5,
|
||||
MarkerType = MarkerType.Circle,
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline,
|
||||
StrokeThickness = 3,
|
||||
};
|
||||
|
||||
var temperatures = new[] { 5, 0, 7, 7, 4, 3, 5, 5, 11, 4, 2, 3, 2, 1, 0, 2, -1, 0, 0, -3, -6, -13, -10, -10, 0, -4, -5, -4, 3, 0, -5 };
|
||||
|
||||
for (int i = 0; i < temperatures.Length; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint(i + 1, temperatures[i]));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Temperature", Unit = "°C", ExtraGridlines = new[] { 0.0 } });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Date" });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Temperatures (Y Axis reversed)")]
|
||||
public static PlotModel TwoColorLineSeriesReversed()
|
||||
{
|
||||
return ThreeColorLineSeries().ReverseYAxis();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="TornadoBarSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
[Examples("TornadoBarSeries"), Tags("Series")]
|
||||
public static class TornadoBarSeriesExamples
|
||||
{
|
||||
[Example("Tornado diagram 1")]
|
||||
[DocumentationExample("Series/TornadoBarSeries")]
|
||||
public static PlotModel TornadoDiagram1()
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Tornado_diagram
|
||||
var model = new PlotModel { Title = "Tornado diagram 1" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new BarSeries
|
||||
{
|
||||
Title = "High",
|
||||
IsStacked = true,
|
||||
FillColor = OxyColor.FromRgb(216, 82, 85),
|
||||
BaseValue = 7,
|
||||
StrokeColor = OxyColors.Black,
|
||||
StrokeThickness = 1
|
||||
};
|
||||
s1.Items.Add(new BarItem(1));
|
||||
s1.Items.Add(new BarItem(1));
|
||||
s1.Items.Add(new BarItem(4));
|
||||
s1.Items.Add(new BarItem(5));
|
||||
|
||||
var s2 = new BarSeries
|
||||
{
|
||||
Title = "Low",
|
||||
IsStacked = true,
|
||||
FillColor = OxyColor.FromRgb(84, 138, 209),
|
||||
BaseValue = 7,
|
||||
StrokeColor = OxyColors.Black,
|
||||
StrokeThickness = 1
|
||||
};
|
||||
s2.Items.Add(new BarItem(-1));
|
||||
s2.Items.Add(new BarItem(-3));
|
||||
s2.Items.Add(new BarItem(-2));
|
||||
s2.Items.Add(new BarItem(-3));
|
||||
|
||||
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
|
||||
categoryAxis.Labels.Add("F/X rate");
|
||||
categoryAxis.Labels.Add("Inflation");
|
||||
categoryAxis.Labels.Add("Price");
|
||||
categoryAxis.Labels.Add("Conversion");
|
||||
var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, ExtraGridlines = new[] { 7.0 } };
|
||||
model.Series.Add(s1);
|
||||
model.Series.Add(s2);
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(valueAxis);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Tornado diagram 2")]
|
||||
public static PlotModel TornadoDiagram2()
|
||||
{
|
||||
var model = new PlotModel { Title = "Tornado diagram 2" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
var s1 = new TornadoBarSeries { Title = "TornadoBarSeries", BaseValue = 7 };
|
||||
s1.Items.Add(new TornadoBarItem { Minimum = 6, Maximum = 8 });
|
||||
s1.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 8 });
|
||||
s1.Items.Add(new TornadoBarItem { Minimum = 5, Maximum = 11 });
|
||||
s1.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 12 });
|
||||
|
||||
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
|
||||
categoryAxis.Labels.Add("F/X rate");
|
||||
categoryAxis.Labels.Add("Inflation");
|
||||
categoryAxis.Labels.Add("Price");
|
||||
categoryAxis.Labels.Add("Conversion");
|
||||
var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, ExtraGridlines = new[] { 7.0 }, MinimumPadding = 0.1, MaximumPadding = 0.1 };
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(valueAxis);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Tornado diagram with various label types")]
|
||||
public static PlotModel TornadoDiagramWithLabels()
|
||||
{
|
||||
var model = new PlotModel { Title = "Tornado Diagram" };
|
||||
var l = new Legend { LegendPlacement = LegendPlacement.Outside };
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Outside};
|
||||
s1.Items.Add(new TornadoBarItem { Minimum = 6, Maximum = 8, CategoryIndex = 0});
|
||||
|
||||
var s2 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Inside };
|
||||
s2.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 8, CategoryIndex = 1 });
|
||||
|
||||
var s3 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Middle };
|
||||
s3.Items.Add(new TornadoBarItem { Minimum = 5, Maximum = 11, CategoryIndex = 2 });
|
||||
|
||||
var s4 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Base };
|
||||
s4.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 12, CategoryIndex = 3 });
|
||||
|
||||
var s5 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Outside, LabelAngle = -45 };
|
||||
s5.Items.Add(new TornadoBarItem { Minimum = 6, Maximum = 8, CategoryIndex = 4 });
|
||||
|
||||
var s6 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Inside, LabelAngle = -45 };
|
||||
s6.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 8, CategoryIndex = 5 });
|
||||
|
||||
var s7 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Middle, LabelAngle = -45 };
|
||||
s7.Items.Add(new TornadoBarItem { Minimum = 5, Maximum = 11, CategoryIndex = 6 });
|
||||
|
||||
var s8 = new TornadoBarSeries { BaseValue = 7, LabelPlacement = LabelPlacement.Base, LabelAngle = -45 };
|
||||
s8.Items.Add(new TornadoBarItem { Minimum = 4, Maximum = 12, CategoryIndex = 7 });
|
||||
|
||||
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 };
|
||||
categoryAxis.Labels.Add("Labels Outside");
|
||||
categoryAxis.Labels.Add("Labels Inside");
|
||||
categoryAxis.Labels.Add("Labels Middle");
|
||||
categoryAxis.Labels.Add("Labels Base");
|
||||
categoryAxis.Labels.Add("Labels Outside (angled)");
|
||||
categoryAxis.Labels.Add("Labels Inside (angled)");
|
||||
categoryAxis.Labels.Add("Labels Middle (angled)");
|
||||
categoryAxis.Labels.Add("Labels Base (angled)");
|
||||
|
||||
var valueAxis = new LinearAxis
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
ExtraGridlines = new[] { 7.0 },
|
||||
MinimumPadding = 0.1,
|
||||
MaximumPadding = 0.1
|
||||
};
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Series.Add(s2);
|
||||
model.Series.Add(s3);
|
||||
model.Series.Add(s4);
|
||||
model.Series.Add(s5);
|
||||
model.Series.Add(s6);
|
||||
model.Series.Add(s7);
|
||||
model.Series.Add(s8);
|
||||
|
||||
model.Axes.Add(categoryAxis);
|
||||
model.Axes.Add(valueAxis);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="TwoColorAreaSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the <see cref="TwoColorAreaSeries" />.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="TwoColorAreaSeries" />.
|
||||
/// </summary>
|
||||
[Examples("TwoColorAreaSeries"), Tags("Series")]
|
||||
public class TwoColorAreaSeriesExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures by a red/blue area chart.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Temperatures")]
|
||||
public static PlotModel TwoColorAreaSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "TwoColorAreaSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TwoColorAreaSeries
|
||||
{
|
||||
Title = "Temperature at Eidesmoen, December 1986.",
|
||||
TrackerFormatString = "December {2:0}: {4:0.0} °C",
|
||||
Color = OxyColors.Tomato,
|
||||
Color2 = OxyColors.LightBlue,
|
||||
MarkerFill = OxyColors.Tomato,
|
||||
MarkerFill2 = OxyColors.LightBlue,
|
||||
StrokeThickness = 2,
|
||||
Limit = -1,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 3,
|
||||
};
|
||||
|
||||
var temperatures = new[] { 5, 0, 7, 7, 4, 3, 5, 5, 11, 4, 2, 3, 2, 1, 0, 2, -1, 0, 0, -3, -6, -13, -10, -10, 0, -4, -5, -4, 3, 0, -5 };
|
||||
|
||||
for (int i = 0; i < temperatures.Length; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint(i + 1, temperatures[i]));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Temperature", Unit = "°C", ExtraGridlines = new[] { 0.0 } });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Date" });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures by a red/blue area chart.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Temperatures ver2")]
|
||||
[DocumentationExample("Series/TwoColorAreaSeries")]
|
||||
public static PlotModel TwoColorAreaSeries2()
|
||||
{
|
||||
var model = new PlotModel { Title = "TwoColorAreaSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TwoColorAreaSeries
|
||||
{
|
||||
Title = "Temperature at Eidesmoen, December 1986.",
|
||||
TrackerFormatString = "December {2:0}: {4:0.0} °C",
|
||||
Color = OxyColors.Black,
|
||||
Color2 = OxyColors.Brown,
|
||||
MarkerFill = OxyColors.Red,
|
||||
Fill = OxyColors.Tomato,
|
||||
Fill2 = OxyColors.LightBlue,
|
||||
MarkerFill2 = OxyColors.Blue,
|
||||
MarkerStroke = OxyColors.Brown,
|
||||
MarkerStroke2 = OxyColors.Black,
|
||||
StrokeThickness = 2,
|
||||
Limit = 0,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 3,
|
||||
};
|
||||
|
||||
var temperatures = new[] { 5, 0, 7, 7, 4, 3, 5, 5, 11, 4, 2, 3, 2, 1, 0, 2, -1, 0, 0, -3, -6, -13, -10, -10, 0, -4, -5, -4, 3, 0, -5 };
|
||||
|
||||
for (int i = 0; i < temperatures.Length; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint(i + 1, temperatures[i]));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Temperature", Unit = "°C", ExtraGridlines = new[] { 0.0 } });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Date" });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures by a red/blue area chart.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Temperatures ver3")]
|
||||
public static PlotModel TwoColorAreaSeries3()
|
||||
{
|
||||
var model = new PlotModel { Title = "TwoColorAreaSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TwoColorAreaSeries
|
||||
{
|
||||
Title = "Temperature at Eidesmoen, December 1986.",
|
||||
TrackerFormatString = "December {2:0}: {4:0.0} °C",
|
||||
Color = OxyColors.Black,
|
||||
Color2 = OxyColors.Brown,
|
||||
MarkerFill = OxyColors.Red,
|
||||
Fill = OxyColors.Tomato,
|
||||
Fill2 = OxyColors.LightBlue,
|
||||
MarkerFill2 = OxyColors.Blue,
|
||||
MarkerStroke = OxyColors.Brown,
|
||||
MarkerStroke2 = OxyColors.Black,
|
||||
StrokeThickness = 1,
|
||||
Limit = 0,
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 1,
|
||||
};
|
||||
|
||||
var temperatures = new[] { 5, 0, 7, 7, 4, 3, 5, 5, 11, 4, 2, 3, 2, 1, 0, 2, -1, 0, 0, -3, -6, -13, -10, -10, 0, -4, -5, -4, 3, 0, -5 };
|
||||
|
||||
for (int i = 0; i < temperatures.Length; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint(i + 1, temperatures[i]));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Temperature", Unit = "°C", ExtraGridlines = new[] { 0.0 } });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Date" });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures by a red/blue area chart.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Two polygons")]
|
||||
public static PlotModel TwoColorAreaSeriesTwoPolygons()
|
||||
{
|
||||
var model = new PlotModel { Title = "Two polygons" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TwoColorAreaSeries
|
||||
{
|
||||
Color = OxyColors.Tomato,
|
||||
Color2 = OxyColors.LightBlue,
|
||||
MarkerFill = OxyColors.Tomato,
|
||||
MarkerFill2 = OxyColors.LightBlue,
|
||||
StrokeThickness = 2,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 3,
|
||||
};
|
||||
|
||||
s1.Points.AddRange(new []{new DataPoint(0, 3), new DataPoint(1, 5), new DataPoint(2, 1), new DataPoint(3, 0), new DataPoint(4, 3) });
|
||||
s1.Points2.AddRange(new[] { new DataPoint(0, -3), new DataPoint(1, -1), new DataPoint(2, 0), new DataPoint(3, -6), new DataPoint(4, -4) });
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom});
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="TwoColorLineSeriesExamples.cs" company="OxyPlot">
|
||||
// Copyright (c) 2014 OxyPlot contributors
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Provides examples for the <see cref="TwoColorLineSeries" />.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using ExampleLibrary.Utilities;
|
||||
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
/// <summary>
|
||||
/// Provides examples for the <see cref="TwoColorLineSeries" />.
|
||||
/// </summary>
|
||||
[Examples("TwoColorLineSeries"), Tags("Series")]
|
||||
public class TwoColorLineSeriesExamples
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an example showing temperatures by a red/blue line.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="PlotModel" />.</returns>
|
||||
[Example("Temperatures")]
|
||||
[DocumentationExample("Series/TwoColorLineSeries")]
|
||||
public static PlotModel TwoColorLineSeries()
|
||||
{
|
||||
var model = new PlotModel { Title = "TwoColorLineSeries" };
|
||||
var l = new Legend
|
||||
{
|
||||
LegendSymbolLength = 24
|
||||
};
|
||||
|
||||
model.Legends.Add(l);
|
||||
|
||||
var s1 = new TwoColorLineSeries
|
||||
{
|
||||
Title = "Temperature at Eidesmoen, December 1986.",
|
||||
TrackerFormatString = "December {2:0}: {4:0.0} °C",
|
||||
Color = OxyColors.Red,
|
||||
Color2 = OxyColors.LightBlue,
|
||||
StrokeThickness = 3,
|
||||
Limit = 0,
|
||||
InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline,
|
||||
MarkerType = MarkerType.Circle,
|
||||
MarkerSize = 4,
|
||||
MarkerStroke = OxyColors.Black,
|
||||
MarkerStrokeThickness = 1.5,
|
||||
};
|
||||
|
||||
var temperatures = new[] { 5, 0, 7, 7, 4, 3, 5, 5, 11, 4, 2, 3, 2, 1, 0, 2, -1, 0, 0, -3, -6, -13, -10, -10, 0, -4, -5, -4, 3, 0, -5 };
|
||||
|
||||
for (int i = 0; i < temperatures.Length; i++)
|
||||
{
|
||||
s1.Points.Add(new DataPoint(i + 1, temperatures[i]));
|
||||
}
|
||||
|
||||
model.Series.Add(s1);
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Temperature", Unit = "°C", ExtraGridlines = new[] { 0.0 } });
|
||||
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Date" });
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Temperatures (Y Axis reversed)")]
|
||||
public static PlotModel TwoColorLineSeriesReversed()
|
||||
{
|
||||
return TwoColorLineSeries().ReverseYAxis();
|
||||
}
|
||||
}
|
||||
}
|
||||
165
Source/Examples/ExampleLibrary/Series/VectorSeriesExamples.cs
Normal file
165
Source/Examples/ExampleLibrary/Series/VectorSeriesExamples.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
namespace ExampleLibrary
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
||||
[Examples("VectorSeries"), Tags("Series")]
|
||||
public static class VectorSeriesExamples
|
||||
{
|
||||
private static readonly Func<double, double, double> dpeaksdx = (x, y) =>
|
||||
-10 * ((1 / 5 - 3 * Math.Pow(x, 2)) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(y, 2)) - 2 * x * (x / 5 - Math.Pow(x, 3) - Math.Pow(y, 5)) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(y, 2))) + 0.6666666666666666 * (1 + x) * Math.Exp(-Math.Pow(1 + x, 2) - Math.Pow(y, 2)) + 3 * (-2 * (1 - x) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(1 + y, 2)) - 2 * x * Math.Pow(1 - x, 2) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(1 + y, 2)));
|
||||
|
||||
private static readonly Func<double, double, double> dpeaksdy = (x, y) =>
|
||||
-10 * (-5 * Math.Pow(y, 4) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(y, 2)) - 2 * y * (x / 5 - Math.Pow(x, 3) - Math.Pow(y, 5)) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(y, 2))) + 0.6666666666666666 * y * Math.Exp(-Math.Pow(1 + x, 2) - Math.Pow(y, 2)) - 6 * Math.Pow(1 - x, 2) * (1 + y) * Math.Exp(-Math.Pow(x, 2) - Math.Pow(1 + y, 2));
|
||||
|
||||
[Example("VectorSeries")]
|
||||
public static PlotModel FromItems()
|
||||
{
|
||||
var model = GetModel(true, out _);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("VectorSeries (Veeness = 2)")]
|
||||
public static PlotModel FromItemsVeeness()
|
||||
{
|
||||
var model = GetModel(true, out var series);
|
||||
series.ArrowVeeness = 2;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("VectorSeries (Vector Origin and Label position)")]
|
||||
public static PlotModel FromItemsVectorOriginAndLabelPosition()
|
||||
{
|
||||
var model = GetModel(true, out var series);
|
||||
series.ArrowLabelPosition = 0.25;
|
||||
series.ArrowStartPosition = 0.5;
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("VectorSeries (without ColorAxis)")]
|
||||
public static PlotModel FromItemsWithoutColorAxis()
|
||||
{
|
||||
var model = GetModel(false, out _);
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("Vector Field")]
|
||||
[DocumentationExample("Series/VectorSeries")]
|
||||
public static PlotModel VectorField()
|
||||
{
|
||||
var model = new PlotModel { Title = "Peaks (Gradient)" };
|
||||
var vs = new VectorSeries();
|
||||
var columnCoordinates = ArrayBuilder.CreateVector(-3, 3, 0.25);
|
||||
var rowCoordinates = ArrayBuilder.CreateVector(-3.1, 3.1, 0.25);
|
||||
vs.ArrowVeeness = 1;
|
||||
vs.ArrowStartPosition = 0.5;
|
||||
vs.ItemsSource = columnCoordinates.SelectMany(x => rowCoordinates.Select(y => new VectorItem(new DataPoint(x, y), new DataVector(dpeaksdx(x, y) / 40, dpeaksdy(x, y) / 40), double.NaN))).ToList();
|
||||
model.Series.Add(vs);
|
||||
return model;
|
||||
}
|
||||
|
||||
private static PlotModel GetModel(bool includeColorAxis, out VectorSeries series)
|
||||
{
|
||||
const int NumberOfItems = 100;
|
||||
var model = new PlotModel { Title = "VectorSeries (Veeness = 2)" };
|
||||
|
||||
var rand = new Random(1);
|
||||
var w = 100.0;
|
||||
var h = 100.0;
|
||||
var max = 10.0;
|
||||
|
||||
if (includeColorAxis)
|
||||
{
|
||||
model.Axes.Add(new LinearColorAxis
|
||||
{
|
||||
Position = AxisPosition.Right,
|
||||
Palette = new OxyPalette(OxyPalettes.Cool(10).Colors.Select(c => OxyColor.FromAColor(100, c))),
|
||||
Minimum = 0.0,
|
||||
Maximum = max,
|
||||
});
|
||||
}
|
||||
|
||||
model.Axes.Add(new LinearAxis()
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = -max,
|
||||
Maximum = w + max,
|
||||
});
|
||||
|
||||
model.Axes.Add(new LinearAxis()
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
Minimum = -max,
|
||||
Maximum = h + max,
|
||||
});
|
||||
|
||||
series = new VectorSeries() { LabelFontSize = 12 };
|
||||
for (int i = NumberOfItems - 1; i >= 0; i--)
|
||||
{
|
||||
var ang = rand.NextDouble() * Math.PI * 2.0;
|
||||
var mag = rand.NextDouble() * max;
|
||||
|
||||
var origin = new DataPoint(rand.NextDouble() * w, rand.NextDouble() * h);
|
||||
var direction = new DataVector(Math.Cos(ang) * mag, Math.Sin(ang) * mag);
|
||||
series.Items.Add(new VectorItem(origin, direction, mag));
|
||||
}
|
||||
|
||||
model.Series.Add(series);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
[Example("VectorSeries on Log Axis")]
|
||||
[DocumentationExample("Series/VectorSeries")]
|
||||
public static PlotModel LogarithmicYAxis()
|
||||
{
|
||||
const int NumberOfItems = 100;
|
||||
var model = new PlotModel { Title = "VectorSeries" };
|
||||
|
||||
var rand = new Random(1);
|
||||
var w = 100.0;
|
||||
var h = 100.0;
|
||||
var max = 50.0;
|
||||
|
||||
model.Axes.Add(new LinearColorAxis
|
||||
{
|
||||
Position = AxisPosition.Right,
|
||||
Palette = OxyPalettes.Cool(10),
|
||||
Minimum = 0.0,
|
||||
Maximum = max,
|
||||
});
|
||||
|
||||
model.Axes.Add(new LinearAxis()
|
||||
{
|
||||
Position = AxisPosition.Bottom,
|
||||
Minimum = -max,
|
||||
Maximum = w + max,
|
||||
});
|
||||
model.Axes.Add(new LogarithmicAxis()
|
||||
{
|
||||
Position = AxisPosition.Left,
|
||||
Minimum = 1,
|
||||
Maximum = h + max,
|
||||
});
|
||||
|
||||
var s = new VectorSeries() { LabelFontSize = 12 };
|
||||
for (int i = NumberOfItems - 1; i >= 0; i--)
|
||||
{
|
||||
var ang = rand.NextDouble() * Math.PI * 2.0;
|
||||
var mag = rand.NextDouble() * max;
|
||||
|
||||
var origin = new DataPoint(rand.NextDouble() * w, rand.NextDouble() * h + 1);
|
||||
var direction = new DataVector(Math.Cos(ang) * mag, Math.Sin(ang) * mag);
|
||||
s.Items.Add(new VectorItem(origin, direction, mag));
|
||||
}
|
||||
|
||||
model.Series.Add(s);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user