简体   繁体   中英

Xamarin.iOS iOS-Charts: Bar Chart not showing bars

I'm using iOSCharts in project to draw bar chart. There's no official documentations available for iOSCharts and on the github page it says all the api's are same as MPAndroidChart plot. I followed everything I used to do in the android, but bars of the bar chart are not showing. The entire chart takes up the color of the bars

This is how it's showing..

在此输入图像描述

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; 
}

I had no trouble using MPAndroidChart in Xamarin.Drioid. Am I something wrong here?

BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i]);
                    yDataSet.SetColor(UIColor.Red);

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM