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

Bar Chart Demo One Label One Color #2792

Closed
c-ys opened this issue Sep 16, 2017 · 0 comments
Closed

Bar Chart Demo One Label One Color #2792

c-ys opened this issue Sep 16, 2017 · 0 comments

Comments

@c-ys
Copy link

c-ys commented Sep 16, 2017

  In the Bar Chart Demo, I want to do that like one barColor represents one company.
  So I put it only one color in every dataSet.
  The result is shown in the figure, the Colors describe is achieved.
  But the barColors are all the same.Could you help me to solve it? What can I do for it?Thx.

d692f4fc-8589-40ac-acb9-6a249cdcdddf

that is my function "- (void)setDataCount:(int)count range:(double)range" in the file "BarChartViewController.m" .

NSMutableArray *yVals = [[NSMutableArray alloc] init];
 double start = 1.0;
for (int i = start; i < start + count + 1; i++)
{
    double mult = (range + 1);
    double val = (double) (arc4random_uniform(mult));
    if (arc4random_uniform(100) < 25) {
        [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:val icon: [UIImage imageNamed:@"icon"]]];
    } else {
        [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:val]];
    }
}

BarChartDataSet *set1 = nil;
if (_chartView.data.dataSetCount > 0)
{
    set1 = (BarChartDataSet *)_chartView.data.dataSets[0];
    set1.values = yVals;
    [_chartView.data notifyDataChanged];
    [_chartView notifyDataSetChanged];
}
else
{


    NSMutableArray *dataSets = [[NSMutableArray alloc] init];

    for (int b = 0 ; b<4; b++) {
        BarChartDataSet *set = [[BarChartDataSet alloc] initWithValues:yVals label:[NSString stringWithFormat:@"company-%d",b+1]];
        NSArray *arr = [NSArray arrayWithObject:ChartColorTemplates.material[(b +1)%4]];
        [set setColors:arr];
        set.drawIconsEnabled = NO;
        [dataSets addObject:set];
    }
    
    BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
    
    data.barWidth = 0.9f;
    
    _chartView.data = data;
}
@c-ys c-ys closed this as completed Sep 18, 2017
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