Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set strings as values in x axis of linechart #3195

Closed
akshaynexus opened this issue Jan 19, 2018 · 1 comment
Closed

Unable to set strings as values in x axis of linechart #3195

akshaynexus opened this issue Jan 19, 2018 · 1 comment

Comments

@akshaynexus
Copy link

Here is my project: https://github.com/akshaynexus/CryptoEye-iOS
so i implemented your chart lib successfully,but when i need to use a array that contains strings that should be used in the xAxis vales,i tried using [ChartIndexAxisValueFormatter withValues:array];,it just results in no values for x axis,the array "array" does contain strings.

screen shot 2018-01-19 at 1 34 12 pm
`LineChartView *linechart =[[LineChartView alloc] initWithFrame:self.refView4Chart.frame];

LineChartDataSet *dataset = (LineChartDataSet *)linechart.data.dataSets[0];
dataset = [[LineChartDataSet alloc] initWithValues:values label:@"DataSet 1"];
dataset.values = values;
dataset.drawValuesEnabled = FALSE;
dataset.drawCirclesEnabled = FALSE;
dataset.fillColor = [UIColor greenColor];
dataset.highlightColor = [UIColor whiteColor];
linechart.noDataTextColor = [UIColor whiteColor];
[dataset setColor:[UIColor greenColor]];
linechart.xAxis.labelPosition = XAxisLabelPositionBottom;
linechart.xAxis.labelTextColor = [UIColor whiteColor];
linechart.leftAxis.labelTextColor = [UIColor whiteColor];
[linechart.rightAxis setEnabled:NO];
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:dataset];
            NSMutableArray *array = [[NSMutableArray alloc] init];
//            array = time4graph;
//            for (NSMutableArray *tempObject in price4rmapi) {
//
//                [array addObject:[tempObject objectAtIndex:0]]];
//            }
            for (int index = 0; index <[time4graph count]; index++) {
                NSString *time = [NSString stringWithFormat:@"%@",[time4graph objectAtIndex:index]];
                double unixTimeStamp =[time doubleValue];
                NSTimeInterval timeInterval=unixTimeStamp/1000;
                NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
                NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
                [dateformatter setLocale:[NSLocale currentLocale]];
                [dateformatter setDateFormat:@"dd-MM-yyyy"];
                NSString *dateString=[dateformatter stringFromDate:date];
                array[index] = [NSString stringWithFormat:@"%@",dateString] ;
            }

LineChartData *data = [[LineChartData alloc] initWithDataSets:dataSets];
[linechart.xAxis setLabelCount:array.count force:TRUE];
linechart.xAxis.valueFormatter = [ChartIndexAxisValueFormatter withValues:array];
linechart.xAxis.drawLabelsEnabled = TRUE;
linechart.data = data;
[self.view addSubview:linechart];`

screen shot 2018-01-19 at 1 36 09 pm

@akshaynexus
Copy link
Author

I just checked the Demo projects and imported the obj c formatters to my project and fixed the issue.thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant