Skip to content

Commit e089d8a

Browse files
author
Curt Mullin
committed
Adding Png Exporter and examples for use .net standard 2.0 applications
1 parent e17a2cf commit e089d8a

File tree

10 files changed

+992
-44
lines changed

10 files changed

+992
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
### Added
6+
- added .NET Core port of PngExporter
7+
58
### Added
69
- New PolarPlot filling the full plot area (#1056)
710

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Chase Long <chaselfromal@gmail.com>
2626
Choden Konigsmark <choden.konigsmark@gmail.com>
2727
classicboss302
2828
csabar <rumancsabi@gmail.com>
29+
Curt Mullin <curt.mullin@gmail.com>
2930
Cyril Martin <cyril.martin.cm@gmail.com>
3031
Dan Aizenstros
3132
darrelbrown

README.md

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
OxyPlot is a cross-platform plotting library for .NET
22

3-
- [Web page](http://oxyplot.org)
4-
- [Documentation](http://docs.oxyplot.org/)
5-
- [Announcements](http://oxyplot.org/announcements) / [atom](http://oxyplot.org/atom.xml)
6-
- [Discussion forum](http://discussion.oxyplot.org)
7-
- [Source repository](http://github.com/oxyplot/oxyplot)
8-
- [Issue tracker](http://github.com/oxyplot/oxyplot/issues)
9-
- [NuGet packages](http://www.nuget.org/packages?q=oxyplot)
10-
- [Stack Overflow](http://stackoverflow.com/questions/tagged/oxyplot)
11-
- [Twitter](https://twitter.com/hashtag/oxyplot)
12-
- [Gitter](https://gitter.im/oxyplot/oxyplot) (chat)
13-
14-
![License](https://img.shields.io/badge/license-MIT-red.svg)
15-
[![Build status](https://img.shields.io/appveyor/ci/objorke/oxyplot/develop.svg)](https://ci.appveyor.com/project/objorke/oxyplot)
3+
- [Web page](http://oxyplot.org)\
4+
- [Documentation](http://docs.oxyplot.org/)
5+
- [Announcements](http://oxyplot.org/announcements) / [atom](http://oxyplot.org/atom.xml)
6+
- [Discussion forum](http://discussion.oxyplot.org)
7+
- [Source repository](http://github.com/oxyplot/oxyplot)
8+
- [Issue tracker](http://github.com/oxyplot/oxyplot/issues)
9+
- [NuGet packages](http://www.nuget.org/packages?q=oxyplot)
10+
- [Stack Overflow](http://stackoverflow.com/questions/tagged/oxyplot)
11+
- [Twitter](https://twitter.com/hashtag/oxyplot)
12+
- [Gitter](https://gitter.im/oxyplot/oxyplot) (chat)
13+
14+
![License](https://img.shields.io/badge/license-MIT-red.svg) [![Build status](https://img.shields.io/appveyor/ci/objorke/oxyplot/develop.svg)](https://ci.appveyor.com/project/objorke/oxyplot)
1615

1716
![Plot](http://oxyplot.org/public/images/normal-distributions.png)
1817

1918
#### Getting started
2019

21-
1. Use the NuGet package manager to add a reference to OxyPlot (see details below if you want to use pre-release packages)
22-
2. Add a `PlotView` to your user interface
23-
3. Create a `PlotModel` in your code
24-
4. Bind the `PlotModel` to the `Model` property of your `PlotView`
20+
1. Use the NuGet package manager to add a reference to OxyPlot (see details below if you want to use pre-release packages)
21+
2. Add a `PlotView` to your user interface
22+
3. Create a `PlotModel` in your code
23+
4. Bind the `PlotModel` to the `Model` property of your `PlotView`
2524

2625
#### Examples
2726

2827
You can find examples in the `/Source/Examples` folder in the code repository.
2928

3029
#### NuGet packages
3130

32-
The latest pre-release packages are pushed by AppVeyor CI to [myget.org](https://www.myget.org/)
33-
To install these packages, set the myget.org package source `https://www.myget.org/F/oxyplot` and remember the "-pre" flag.
34-
35-
The stable release packages will be pushed to [nuget.org](https://www.nuget.org/packages?q=oxyplot).
36-
Note that we have currently have a lot of old (v2015.*) and pre-release packages on this feed, this will be cleaned up as soon as we release [v1.0](https://github.com/oxyplot/oxyplot/milestones/v1.0).
37-
38-
Package | Targets | Dependencies
39-
--------|---------|-------------
40-
OxyPlot.Core | .NET Standard 1.0 |
41-
OxyPlot.Wpf | .NET 4.5.2 |
42-
OxyPlot.WindowsForms | .NET 4.5.2 |
43-
OxyPlot.Windows | Universal Windows 10.0 |
44-
OxyPlot.GtkSharp | .NET 4.5.2 | GTK# 2
45-
OxyPlot.GtkSharp3 | .NET 4.5.2 | GTK# 3
46-
OxyPlot.Xamarin.Android | MonoAndroid |
47-
OxyPlot.Xamarin.iOS | MonoTouch and iOS10 |
48-
OxyPlot.Xamarin.Mac | Mac20 |
49-
OxyPlot.Xamarin.Forms | MonoTouch, iOS10, MonoAndroid, WP8 |
50-
OxyPlot.Xwt | .NET 4.5.2 |
51-
OxyPlot.SharpDX.Wpf | .NET 4.5.2 |
52-
OxyPlot.Avalonia | .NET 4.5.2 |
53-
OxyPlot.OpenXML | .NET 4.5.2 |
54-
OxyPlot.Pdf | .NET 4.5.2 | PdfSharp
55-
OxyPlot.Contrib | .NET Standard 1.0 |
56-
OxyPlot.ExampleLibrary | .NET Standard 1.0 |
31+
The latest pre-release packages are pushed by AppVeyor CI to [myget.org](https://www.myget.org/) To install these packages, set the myget.org package source `https://www.myget.org/F/oxyplot` and remember the "-pre" flag.
32+
33+
The stable release packages will be pushed to [nuget.org](https://www.nuget.org/packages?q=oxyplot). Note that we have currently have a lot of old (v2015.\*) and pre-release packages on this feed, this will be cleaned up as soon as we release [v1.0](https://github.com/oxyplot/oxyplot/milestones/v1.0).
34+
35+
| Package | Targets | Dependencies |
36+
|-------------------------|------------------------------------|--------------|
37+
| OxyPlot.Core | .NET Standard 1.0 | |
38+
| OxyPlot.Core.Drawing | .NET Standard 2.0 | |
39+
| OxyPlot.Wpf | .NET 4.5.2 | |
40+
| OxyPlot.WindowsForms | .NET 4.5.2 | |
41+
| OxyPlot.Windows | Universal Windows 10.0 | |
42+
| OxyPlot.GtkSharp | .NET 4.5.2 | GTK\# 2 |
43+
| OxyPlot.GtkSharp3 | .NET 4.5.2 | GTK\# 3 |
44+
| OxyPlot.Xamarin.Android | MonoAndroid | |
45+
| OxyPlot.Xamarin.iOS | MonoTouch and iOS10 | |
46+
| OxyPlot.Xamarin.Mac | Mac20 | |
47+
| OxyPlot.Xamarin.Forms | MonoTouch, iOS10, MonoAndroid, WP8 | |
48+
| OxyPlot.Xwt | .NET 4.5.2 | |
49+
| OxyPlot.SharpDX.Wpf | .NET 4.5.2 | |
50+
| OxyPlot.Avalonia | .NET 4.5.2 | |
51+
| OxyPlot.OpenXML | .NET 4.5.2 | |
52+
| OxyPlot.Pdf | .NET 4.5.2 | PdfSharp |
53+
| OxyPlot.Contrib | .NET Standard 1.0 | |
54+
| OxyPlot.ExampleLibrary | .NET Standard 1.0 | |
5755

5856
#### Contribute
5957

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<StartupObject>OxyPlot.DotNetCore.Drawing.Example.Program</StartupObject>
7+
<AssemblyName>OxyPlot.DotNetCore.Drawing.Example</AssemblyName>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="OxyPlot.Core" Version="2.0.0-unstable1059" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\OxyPlot.Core.Drawing\OxyPlot.Core.Drawing.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.Drawing;
3+
using System.IO;
4+
using System.Linq;
5+
using OxyPlot;
6+
using OxyPlot.Axes;
7+
using OxyPlot.Core.Drawing;
8+
using OxyPlot.Series;
9+
10+
namespace Core.Drawing.Example
11+
{
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
17+
try
18+
{
19+
var outputUsingMemStream = "test-oxyplot-memstream.png";
20+
var outputToFile = "test-oxyplot-file.png";
21+
var outputExportFileStream = "test-oxyplot-stream-export.png";
22+
var outputExportFileOOP = "test-oxyplot-ExportToFile.png";
23+
24+
var width = 1024;
25+
var height = 768;
26+
27+
var model = BuildPlotModel();
28+
29+
30+
PngExporter.Export(model, outputToFile, width, height, Brushes.White);
31+
32+
using(var stream = new MemoryStream())
33+
{
34+
PngExporter.Export(model, stream, width, height, OxyColors.White, 96);
35+
System.IO.File.WriteAllBytes(outputUsingMemStream, stream.ToArray());
36+
}
37+
38+
using (var pngStream = PngExporter.ExportToStream(model, width, height, OxyColors.White))
39+
{
40+
var fileStream = new System.IO.FileStream(outputExportFileStream, FileMode.Create);
41+
pngStream.CopyTo(fileStream);
42+
fileStream.Flush();
43+
}
44+
45+
var stream2 = new MemoryStream();
46+
var pngExporter = new PngExporter { Width = width, Height = height, Background = OxyColors.White };
47+
pngExporter.Export(model, stream2);
48+
49+
// Write to a file, OOP
50+
var pngExporter2 = new PngExporter { Width = width, Height = height, Background = OxyColors.White };
51+
pngExporter2.ExportToFile(model, outputExportFileOOP);
52+
}
53+
catch(Exception ex)
54+
{
55+
56+
}
57+
}
58+
59+
private static IPlotModel BuildPlotModel()
60+
{
61+
var rand = new Random();
62+
63+
var model = new PlotModel {Title = "Cake Type Popularity"};
64+
65+
var cakePopularity = Enumerable.Range(1,5).Select(i => rand.NextDouble()).ToArray();
66+
var sum = cakePopularity.Sum();
67+
var barSeries = new BarSeries
68+
{
69+
ItemsSource = cakePopularity.Select(cp => RandomBarItem(cp, sum)),
70+
LabelPlacement = LabelPlacement.Base,
71+
LabelFormatString = "{0:.00}%"
72+
};
73+
74+
model.Series.Add(barSeries);
75+
76+
model.Axes.Add(new CategoryAxis
77+
{
78+
Position = AxisPosition.Left,
79+
Key = "CakeAxis",
80+
ItemsSource = new[]
81+
{
82+
"Apple cake",
83+
"Baumkuchen",
84+
"Bundt Cake",
85+
"Chocolate cake",
86+
"Carrot cake"
87+
}
88+
});
89+
return model;
90+
}
91+
92+
private static BarItem RandomBarItem(double cp, double sum)
93+
=> new BarItem {Value = cp / sum * 100, Color = RandomColor()};
94+
95+
private static OxyColor RandomColor()
96+
{
97+
var r = new Random();
98+
return OxyColor.FromRgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)