我正在使用MicroCharts-Barchart在Xamarin表单应用程序中实现图表。我想设置条的宽度以及条之间的间距,但是我找不到设置此属性的任何属性
下面是我正在使用的代码段
Xaml
<forms:ChartView x:Name="Chart4"
HeightRequest="400"
/>
.cs文件代码
public partial class ChartsPage : ContentPage
{
List<Entry> entries = new List<Entry>
{
new Microcharts.Entry(200)
{
Color=SKColor.Parse("#FF1943"),
Label ="January",
ValueLabel = "200",
},
new Entry(400)
{
Color = SKColor.Parse("00BFFF"),
Label = "March",
ValueLabel = "400"
},
new Entry(-100)
{
Color = SKColor.Parse("#00CED1"),
Label = "Octobar",
ValueLabel = "-100"
},
};
public ChartsPage()
{
InitializeComponent();
Chart4.Chart = new BarChart() { Entries = entries };
}
}
它显示如下
如果MicroCharts不具有此功能,请建议是否还有其他库具有此功能。
答案 0 :(得分:1)
XAML:
您需要按以下方式将HorizontalOptions设置为StartAndExpand:
"mytype"
.cs文件代码:
您需要如下设置图表的宽度= NumberOfBars X BarWidth:
<forms:ChartView x:Name="Chart4" HeightRequest="400" HorizontalOptions="StartAndExpand"/>
要设置条形之间的间距,请按如下所示使用“边距”:
public ChartsPage()
{
InitializeComponent();
Chart4.Chart = new BarChart() { Entries = entries };
//Set the WidthRequest of your Chart based on the following calculation.
//Here, barWidth will be the width of the Bar in your Chart
int barWidth = 50;
Chart4.WidthRequest = entries.Count * barWidth;
}
希望这会对您有所帮助。