Skip to content

Commit

Permalink
Merge pull request #2 from seijikun/bar
Browse files Browse the repository at this point in the history
[BarSeries] Add additional simple example
  • Loading branch information
objorke committed Apr 3, 2016
2 parents 8007f83 + c8b5c85 commit af381e3
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions ExampleGenerator/Series/BarSeriesExamples.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,68 @@
namespace ExampleGenerator
using System;
using System.Linq;
using System.Collections.Generic;

namespace ExampleGenerator
{
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

public class BarSeriesExamples
{
[Export(@"Series\BarSeries")]
public static PlotModel BarSeries()


[Export(@"Series\BarSeries")]
public static PlotModel BarSeries()
{

var model = new PlotModel{ Title = "Cake Type Popularity" };

//generate a random percentage distribution between the 5
//cake-types (see axis below)
var rand = new Random();
double[] cakePopularity = new double[5];
for(int i = 0; i < 5; ++i) {
cakePopularity[i] = rand.NextDouble();
}
var sum = cakePopularity.Sum();

var barSeries = new BarSeries
{
ItemsSource = new List<BarItem>(new[]
{
new BarItem{ Value = (cakePopularity[0] / sum * 100) },
new BarItem{ Value = (cakePopularity[1] / sum * 100) },
new BarItem{ Value = (cakePopularity[2] / sum * 100) },
new BarItem{ Value = (cakePopularity[3] / sum * 100) },
new BarItem{ Value = (cakePopularity[4] / sum * 100) }
}),
LabelPlacement = LabelPlacement.Inside,
LabelFormatString = "{0:.00}%"
};
model.Series.Add(barSeries);

model.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Left,
Key = "CakeAxis",
ItemsSource = new[]
{
"Apple cake",
"Baumkuchen",
"Bundt Cake",
"Chocolate cake",
"Carrot cake"
}
});

return model;
}



[Export(@"Series\BarSeries_grouped")]
public static PlotModel BarSeries_grouped()
{
var model = new PlotModel
{
Expand Down Expand Up @@ -42,5 +97,6 @@ public static PlotModel BarSeries()
model.Axes.Add(valueAxis);
return model;
}

}
}
}

0 comments on commit af381e3

Please sign in to comment.