0
在我的xamarin表单应用程序中,我使用了Oxyplot条形图。 Here is the code,这对于单杠条件下的工作,如何创建垂直图形?有没有其他的条形图插件?如何可能Xamarin形式垂直条形图?
在我的xamarin表单应用程序中,我使用了Oxyplot条形图。 Here is the code,这对于单杠条件下的工作,如何创建垂直图形?有没有其他的条形图插件?如何可能Xamarin形式垂直条形图?
关键是要使用ColumnSeries
和ColumnItem
对象。这应该呈现为具有垂直方向条形的条形图。如果你创建一个新的ContentPage
并粘贴下面的代码,你可以看到它的实际运行。我在代码示例下面附加了一张图片,详细说明了它在iOS上的外观。
public partial class DemoPage : ContentPage
{
public DemoPage()
{
InitializeComponent();
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 ColumnSeries
{
ItemsSource = new List<ColumnItem>(new[]
{
new ColumnItem{ Value = (cakePopularity[0]/sum * 100) },
new ColumnItem{ Value = (cakePopularity[1]/sum * 100) },
new ColumnItem{ Value = (cakePopularity[2]/sum * 100) },
new ColumnItem{ Value = (cakePopularity[3]/sum * 100) },
new ColumnItem{ Value = (cakePopularity[4]/sum * 100) }
}),
LabelPlacement = LabelPlacement.Inside,
LabelFormatString = "{0:.00}%"
};
model.Series.Add(barSeries);
model.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Bottom,
Key = "CakeAxis",
ItemsSource = new[]
{
"A",
"B",
"C",
"D",
"E"
}
});
var grid = new Grid();
grid.Children.Add(new PlotView
{
Model = model,
VerticalOptions = LayoutOptions.Center,
HeightRequest = 200,
HorizontalOptions = LayoutOptions.Fill,
});
Content = grid;
}
}
这应该渲染的图形是这样的:
可以这样用棒的组合来完成。 A的3个酒吧,B的3个酒吧等等? – Ph0b0x
不知道tbh,我认为Oxyplot文档应该能够澄清这一点。 –
我发现了Usinsg的“IsStacked”属性和/或堆栈组。 – Ph0b0x