[英]Xamarin Forms OxyPlot for Bar charts
I'm Working on Xamarin.Forms application where I want to implement bar charts as attached in screenshot. 我正在开发Xamarin.Forms应用程序,我想在屏幕截图中附加条形图。 There are no such control in Xamarin.Forms, so I'm using OxyPlot nuget package for that, but the problem is that the bars in oxyplot are Horizontal and there is no option for grid lines inside graph plot.
在Xamarin.Forms中没有这样的控件,所以我正在使用OxyPlot nuget包,但问题是oxyplot中的条形是水平的,并且图形图中没有网格线的选项。 is there any open source Library for the bar graphs so that I can use.
是否有条形码的开源库,以便我可以使用。
You can do it with OxyPlot
using ColumnSeries
. 您可以使用
ColumnSeries
使用OxyPlot
来完成。 Try this MCVE : 试试这个MCVE :
XAML: XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App2"
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
x:Class="App2.MainPage">
<ContentPage.BindingContext>
<local:MyViewModel></local:MyViewModel>
</ContentPage.BindingContext>
<oxy:PlotView Model="{Binding Model}"/>
</ContentPage>
View Model: 查看型号:
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;
public class MyViewModel
{
public PlotModel Model { get; set; }
public MyViewModel()
{
CategoryAxis xaxis = new CategoryAxis();
xaxis.Position = AxisPosition.Bottom;
xaxis.MajorGridlineStyle = LineStyle.Solid;
xaxis.MinorGridlineStyle = LineStyle.Dot;
xaxis.Labels.Add("Mon, 4/24");
xaxis.Labels.Add("Tue, 4/25");
xaxis.Labels.Add("Wed, 4/26");
xaxis.Labels.Add("Thu, 4/27");
LinearAxis yaxis = new LinearAxis();
yaxis.Position = AxisPosition.Left;
yaxis.MajorGridlineStyle = LineStyle.Dot;
xaxis.MinorGridlineStyle = LineStyle.Dot;
ColumnSeries s1 = new ColumnSeries();
s1.IsStacked = true;
s1.Items.Add(new ColumnItem(20));
s1.Items.Add(new ColumnItem(60));
s1.Items.Add(new ColumnItem(40));
s1.Items.Add(new ColumnItem(50));
ColumnSeries s2 = new ColumnSeries();
s2.IsStacked = true;
s2.Items.Add(new ColumnItem(50));
s2.Items.Add(new ColumnItem(30));
s2.Items.Add(new ColumnItem(10));
s2.Items.Add(new ColumnItem(20));
Model = new PlotModel();
Model.Title = "Xamarin Oxyplot Sample";
Model.Background = OxyColors.Gray;
Model.Axes.Add(xaxis);
Model.Axes.Add(yaxis);
Model.Series.Add(s1);
Model.Series.Add(s2);
}
}
I have use this excellent open source library, it has bindings for Xamarin.iOS and Xamarin.Android, you will have to do the custom renderers to display the charts on Xamarin.Forms but it is highly customizable: 我使用了这个优秀的开源库,它有Xamarin.iOS和Xamarin.Android的绑定,你必须做自定义渲染器才能在Xamarin.Forms上显示图表,但它是高度可定制的:
Android: https://github.com/PhilJay/MPAndroidChart Android: https : //github.com/PhilJay/MPAndroidChart
iOS: https://github.com/danielgindi/Charts iOS: https : //github.com/danielgindi/Charts
Xamarin Android: https://github.com/Flash3001/MPAndroidChart.Xamarin Xamarin Android: https : //github.com/Flash3001/MPAndroidChart.Xamarin
Xamarin iOS: https://github.com/Flash3001/iOSCharts.Xamarin Xamarin iOS: https : //github.com/Flash3001/iOSCharts.Xamarin
They are available as NuGet packages. 它们以NuGet包的形式提供。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.