如何解决StackLayout中的ChartView切断Chart
这是我的代码:
List<Entry> entries = new List<Entry>
{
new Entry(7)
{
Color = SKColor.Parse("#166DA3"),},new Entry(3)
{
Color = SKColors.Transparent,}
};
public RoundScore2()
{
Content = _contentLayout; // layout inherited from a different class
Label congrats = new Label
{
Text = "Congratulations!",FontAttributes = FontAttributes.Bold,FontSize = 30,HorizontalOptions = LayoutOptions.CenterAndExpand,VerticalOptions = LayoutOptions.Start,TextColor = Color.Black
};
_contentStack.Children.Add(congrats); // _contentStack inherited from same class,_contentStack is added to _contentLayout
ChartView Chart1 = new ChartView
{
VerticalOptions = LayoutOptions.CenterAndExpand,HeightRequest = 80
};
_contentStack.Children.Add(Chart1);
Chart1.Chart = new DonutChart() { Entries = entries,HoleRadius = 5 };
Button nextRound = new Button
{
Text = "Start Round " + roundCounter.ToString(),Margin = new Thickness(10,20,10,10),TextColor = Color.Black,BackgroundColor = Color.FromHex("48AADF"),FontFamily = "Source Sans Pro",FontSize = 20,CornerRadius = 8,HorizontalOptions = LayoutOptions.Center,VerticalOptions = LayoutOptions.StartAndExpand,WidthRequest = 180
};
_contentStack.Children.Add(nextRound);
}
堆栈溢出使我现在无法添加照片(“无法上传图像;无法到达imgur”)...但是基本上,我只能看到饼图的水平中间部分。图表有足够的空间显示,但已被切断。我尝试将VerticalOptions = LayoutOptions.FillAndExpand
与LayoutOptions.CenterAndExpand
一起设置,但没有运气。有人知道为什么会这样吗?
编辑:即使删除了“标签”和“按钮”,该视图仍被切除。
解决方法
但基本上,我只能看到饼图的水平中间部分。
从ChartView
的共享代码中,我猜测图表视图的宽度是否太小。
ChartView Chart1 = new ChartView
{
VerticalOptions = LayoutOptions.CenterAndExpand,HeightRequest = 80
};
如果这样,您可以添加HorizontalOptions
,如下所示:
ChartView Chart1 = new ChartView
{
VerticalOptions = LayoutOptions.CenterAndExpand,HorizontalOptions = LayoutOptions.FillAndExpand,HeightRequest = 80
};
此外,还可以为HorizontalOptions
添加StackLayout
:
_contentStack.HorizontalOptions = LayoutOptions.FillAndExpand;
_contentStack.VerticalOptions = LayoutOptions.FillAndExpand;
,
在更改VerticalOptions = LayoutOptions.Center
和HorizontalOptions = LayoutOptions.Fill
以及更改HoleRadius = .5f
之后,它仍然有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。