数据集不会加载iOS-Charts

时间:2016-04-25 20:01:59

标签: ios objective-c charts ios-charts

我有一个视图控制器,它只是一个嵌套在导航控制器中的全屏ios-chart视图。这是在10月份工作,我查看了我的git repo并没有改变这个文件。但是我确实从回购中提取了最新版本,并取得了相同的结果。

首先,我有一个设置图表的设置功能:

function myFunction() {
  // Grab your element
  var which = document.getElementById('myP');
  // Hide it if it is explicitly visible or the visbility property is not set,
  // otherwise show it
  which.style.visibility = (which.style.visibility == 'visible' || !which.style.visibility) ? 'hidden' : 'visible';
}

刷新自我从我的网站上抓取JSON并将其形成一个字典数组,然后调用它:

if (vertical)
{
    self.barChart = [[BarChartView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
}
else
{
    self.barChart = [[HorizontalBarChartView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
}
self.barChart.backgroundColor = [UIColor clearColor];
self.barChart.delegate = self;

self.barChart.descriptionText = @"";
self.barChart.noDataTextDescription = @"";

self.barChart.drawBarShadowEnabled = NO;
self.barChart.drawValueAboveBarEnabled = YES;
self.barChart.rightAxis.drawLabelsEnabled = NO;
self.barChart.rightAxis.drawGridLinesEnabled = NO;
self.barChart.maxVisibleValueCount = 60;
self.barChart.pinchZoomEnabled = NO;
self.barChart.drawGridBackgroundEnabled = NO;
self.barChart.backgroundColor = [UIColor whiteColor];
ChartXAxis *xAxis = self.barChart.xAxis;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.labelFont = [UIFont systemFontOfSize:10.f];
xAxis.drawGridLinesEnabled = NO;
xAxis.spaceBetweenLabels = 0;

ChartYAxis *leftAxis = self.barChart.leftAxis;
leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
leftAxis.labelCount = 3;
leftAxis.drawGridLinesEnabled = YES;
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];
leftAxis.valueFormatter.maximumFractionDigits = 0;
leftAxis.valueFormatter.positivePrefix = @"$";
leftAxis.valueFormatter.negativePrefix = @"-$";
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
leftAxis.spaceTop = 0.25;

[self.barChart.legend setEnabled:false];
[self refresh]; //refreshes data for charting

数据集是正确的并获得所有24个值,并且似乎正确设置了xAxis和yAxis但是在此之后,我的图表只显示“没有可用的图表数据” 我一直在搜索并没有找到很多关于此的文章,但有一个建议是使用dispatch_after在条形图上运行setNeedsDisplay:

NSMutableArray *xAxis = [[NSMutableArray alloc] init];
NSMutableArray *yAxis = [[NSMutableArray alloc] init];
for (int x = 0; x < data.count; x++) {
    [xAxis addObject:data[x][@"title"]];
    [yAxis addObject:[[BarChartDataEntry alloc] initWithValue:floor([data[x][@"value"] doubleValue]) xIndex:x]];
}
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yAxis label:self.barTitle];
set1.barSpace = 0.35;
set1.colors = @[[[UIColor alloc] initWithRed:0.007843137255 green:0.2117647059 blue:0.4470588235 alpha:1]];
set1.valueFormatter = [[NSNumberFormatter alloc] init];
set1.valueFormatter.positivePrefix = @"$";
set1.valueFormatter.negativePrefix = @"-$";
[set1.valueFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
set1.valueFormatter.maximumFractionDigits = 0;
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];

BarChartData *barData = [[BarChartData alloc] initWithXVals:xAxis dataSets:dataSets];
[barData setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];

self.barChart.data = barData;

我已经尝试用30秒的代码作为我的计时器,以确保图表库完成了对数据所需的操作,但图表仍然没有显示数据。

任何和所有帮助将不胜感激。提前致谢!

0 个答案:

没有答案