如何在条形图数据上设置x轴 - ios-charts?

时间:2017-01-27 11:00:11

标签: ios charts ios-charts

以前我们可以设置条形图数据的x轴如下: -

BarChartData *data = [[BarChartData alloc] initWithXVals:xvals dataSets:dataSets];

ios-charts库的最新更新中,语法更改为: -             BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];

如何在BarChartData上设置x轴?

2 个答案:

答案 0 :(得分:3)

借助此Answer (swift version),我可以在// docker publish settings import com.amazonaws.regions.{Region, Regions} region in ecr := Region.getRegion(Regions.AP_NORTHEAST_1) repositoryName in ecr := (packageName in Docker).value + ":" + (version in Docker).value localDockerImage in ecr := (packageName in Docker).value + ":" + (version in Docker).value // Publisher Setting //~~~~~~~~~~~~~~~~~~~ import ReleaseTransformations._ releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions, runClean, runTest, setReleaseVersion, commitReleaseVersion, tagRelease, ReleaseStep(state => Project.extract(state).runTask(publishLocal in Docker, state)._1), ReleaseStep(state => Project.extract(state).runTask(login in ecr, state)._1), ReleaseStep(state => Project.extract(state).runTask(push in ecr, state)._1), setNextVersion, commitNextVersion, pushChanges ) lazy val releaseDev = taskKey[Unit]("push docker image") releaseDev := Def.sequential( publishLocal in Docker, login in ecr, push in ecr).value (repositoryName in ecr) in releaseDev := (packageName in Docker).value + "-stg" + ":" + (version in Docker).value 的条形图上显示xAxis字符串值。

Objective-C

设置图表数据。基本示例如下: -

NSMutableArray *xValsDietArray;

实施for (int i=0; i<dietArray.count; i++) { DietInput *obj = [dietArray objectAtIndex:i]; NSString *dateStr = @"Jan"; [xValsDietArray addObject:dateStr];//Maintain this xValsDietArray. It will be used later on while setting x values. This contains array of x-axis values [yvals addObject:[[BarChartDataEntry alloc]initWithX:[[xValsDietArray objectAtIndex:i] doubleValue] y:obj.calorieInput.doubleValue data:xValsDietArray] ]; } BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithValues:yvals label:@"Water Consumed"]; NSMutableArray *dataSets = [[NSMutableArray alloc] init]; [dataSets addObject:set1]; BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; cell.chartView.data=data; cell.chartView.xAxis.valueFormatter = self;// Set the delegate to self. THIS IS THE MAIN ADDITION IN NEW CHART LIBRARY 委托方法,如下所示: -

stringForValue

答案 1 :(得分:1)

您可以使用以下相同的IAxisValueFormatter 方法作为索引,并从xArray中获取数据并在其中显示自定义X values

#pragma mark - IAxisValueFormatter

- (NSString *)stringForValue:(double)value
                        axis:(ChartAxisBase *)axis
{
    NSString *xValue = [xArray objectAtIndex:value];
    return xValue;
}

您可以将其用作IAxisValueFormatter的委托方法。

希望这可以帮助您在图表中设置xAxis。