I'm using OxyPlot to render a bar chart with SkiaSharp. Currently, the bars are getting rendered horizontally, but i'd like them to be rendered vertically.
I tried to swap the AxisPosition
but this led to the following exception:
OxyPlot exception: BarSeries requires a CategoryAxis on the Y Axis.
An exception of type System.Exception was thrown when updating the plot model.
at OxyPlot.Series.BarSeriesBase`1.GetCategoryAxis()
at
OxyPlot.Series.BarSeriesBase`1.OxyPlot.Series.IBarSeries.get_CategoryAxis()
at OxyPlot.PlotModel.<>c.<UpdateBarSeriesManagers>b__238_1(IBarSeries s)
at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector,
IEqualityCom
at System.Linq.GroupedEnumerable`2.GetEnumerator()
at OxyPlot.PlotModel.UpdateBarSeriesManagers()
at OxyPlot.PlotModel.OxyPlot.IPlotModel.Update(Boolean updateData)
I'm currently using this example code snippet from the official repo:
var model = new PlotModel();
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
var valueAxis1 = new LinearAxis
{
Title = "Value Axis 1",
Position = AxisPosition.Bottom,
MinimumPadding = 0.06,
MaximumPadding = 0.06,
ExtraGridlines = new[] {0d},
Key = "x1"
};
model.Axes.Add(categoryAxis);
model.Axes.Add(valueAxis1);
var series = new List<BarSeries>
{
new BarSeries(),
new BarSeries(),
};
var rnd = new Random(1);
foreach (var s in series)
{
for (var i = 0; i < 4; i++)
s.Items.Add(new BarItem() { Value = rnd.Next(0, 100) });
model.Series.Add(s);
}
This is the rendered bar chart:
It looks like this was vertical bars were possible in the past using ColumnSeries
, but this type of series has been removed. Does anyone know how this can be achieved?