C# Xamarin形成条形图的氧化图
我正在开发Xamarin.Forms应用程序,我想在其中实现屏幕截图中附带的条形图。在Xamarin.Forms中没有这样的控件,所以我使用OxyPlot nuget包来实现,但问题是OxyPlot中的条是水平的,并且graph plot中没有网格线选项。是否有任何开放源码的条形图库供我使用。我使用了这个优秀的开放源码库,它为Xamarin.iOS和Xamarin.Android提供了绑定,您必须使用自定义渲染器在Xamarin上显示图表。表单但它是高度可定制的: 安卓: iOS: Xamarin Android: Xamarin iOS:C# Xamarin形成条形图的氧化图,c#,.net,xaml,xamarin.forms,oxyplot,C#,.net,Xaml,Xamarin.forms,Oxyplot,我正在开发Xamarin.Forms应用程序,我想在其中实现屏幕截图中附带的条形图。在Xamarin.Forms中没有这样的控件,所以我使用OxyPlot nuget包来实现,但问题是OxyPlot中的条是水平的,并且graph plot中没有网格线选项。是否有任何开放源码的条形图库供我使用。我使用了这个优秀的开放源码库,它为Xamarin.iOS和Xamarin.Android提供了绑定,您必须使用自定义渲染器在Xamarin上显示图表。表单但它是高度可定制的: 安卓: iOS: Xama
它们以NuGet软件包的形式提供。您可以使用
OxyPlot
使用ColumnSeries
来实现。试试这个:
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>
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);
}
}
您可以检查Syncfusion Xamarin控件,它不是开源的,但有社区许可证。谢谢@jstreet,它可以工作,但当我在stacklayout中使用它时,图形不可见。此外,heightrequest和widthrequest属性未反映任何更改。如果您有新问题,请发布新问题!始终,始终向我们展示您的代码,而不仅仅是图片!