我在项目中使用iOSCharts绘制条形图。没有适用于iOSCharts的官方文档,在github页面上,它表示所有api都与MPAndroidChart图相同。我按照我以前在android中所做的一切,但条形图的条形图没有显示。整个图表占据了条形的颜色
这就是它的表现......
BarChartView barChart = new BarChartView();
ChartXAxis xAxis = barChart.XAxis;
xAxis.LabelPosition = XAxisLabelPosition.Bottom;
xAxis.DrawGridLinesEnabled = false;
xAxis.AxisLineColor = UIColor.Clear.FromHexString("#DEDEDE");
barChart.RightAxis.Enabled = false;
barChart.LeftAxis.DrawAxisLineEnabled = false;
barChart.LeftAxis.GridColor = UIColor.Clear.FromHexString("#DEDEDE");
barChart.LeftAxis.StartAtZeroEnabled = false;
barChart.Legend.Enabled = false;
barChart.LeftAxis.LabelCount = 5;
barChart.BackgroundColor = UIColor.Clear.FromHexString("#FFFFFF");
barChart.GridBackgroundColor = UIColor.Clear.FromHexString("FFFFFF");
barChart.SetDescriptionText("");
barChart.MoveViewToX(7);
VitalGraph vGraph = ..............
barChart.SetData(GetBarData(vGraph.vitalId, vGraph));
barChart.Frame = measurementsChartContainer.Frame;
measurementsChartContainer.AddSubview(barChart);
private BarChartData GetBarData(int vitalId, VitalGraph vGraph)
{
List<float> valueList = vGraph.valueList.Select(x => float.Parse(x)).ToList();
UIColor[] colorList = new UIColor[vGraph.colorList.Count];
for (int i = 0; i < vGraph.colorList.Count; i++)
colorList[i] = UIColor.Clear.FromHexString(vGraph.colorList[i]);
BarChartDataEntry[] entries = new BarChartDataEntry[7];
for (int i = 0; i < valueList.Count; i++)
{
entries[i] = new BarChartDataEntry(valueList[i], i);
}
//barChart.MoveViewToX(valueList.Count)
BarChartDataSet barDataSet = new BarChartDataSet(entries, "Vital Reading");
barDataSet.BarSpace = 40f;
NSString[] dayList = new NSString[vGraph.dayList.Count];
for (int i = 0; i < vGraph.dayList.Count; i++)
dayList[i] = new NSString(vGraph.dayList[i]);
List<IBarChartDataSet> dataList = new List<IBarChartDataSet>();
dataList.Add(barDataSet);
BarChartData barData = new BarChartData(dayList, dataList.ToArray());
//barDataSet.SetColors(colorList);
return barData;
}
我在Xamarin.Drioid中使用MPAndroidChart没有问题。我错了吗?
答案 0 :(得分:0)
BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i]);
yDataSet.SetColor(UIColor.Red);
希望它对你有所帮助。