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

Line is drawn below the x axis when the drawCubicEnabled is YES. #1236

Closed
VincentSit opened this issue Jul 8, 2016 · 5 comments
Closed

Line is drawn below the x axis when the drawCubicEnabled is YES. #1236

VincentSit opened this issue Jul 8, 2016 · 5 comments

Comments

@VincentSit
Copy link
Contributor

qq20160708-0 2x

simulator_screen_shot_jul_8__2016__5_43_58_pm

I don't want to draw the line below the x axis when the drawCubicEnabled is YES.

There is also another problem. If the value is 0, I want to skip it, but I do not know how to do.

In addition, I do not want to it filled below the x-axis, I expect a result like this:

simulator-screen-shot-jul-8 -2016 -5 43 58-pm

Here is my code.

    _chartView = [[LineChartView alloc] initWithFrame:CGRectZero];
    _chartView.delegate = self;
    _chartView.descriptionText = @"";
    _chartView.noDataTextDescription = @"You need to provide data for the chart.";
    _chartView.leftAxis.labelFont = font;
    _chartView.leftAxis.labelTextColor = [UIColor ibl_colorWithRGB:188];
    _chartView.leftAxis.axisLineColor = color;
    _chartView.leftAxis.drawAxisLineEnabled = NO;
    _chartView.leftAxis.drawZeroLineEnabled = YES;
    _chartView.leftAxis.drawGridLinesEnabled = NO;
    _chartView.leftAxis.drawTopYLabelEntryEnabled = YES;
    _chartView.leftAxis.valueFormatter = _valueFormatter;
    _chartView.xAxis.labelPosition = XAxisLabelPositionBottom;
    _chartView.xAxis.gridColor = color;
    _chartView.xAxis.labelFont = font;
    _chartView.rightAxis.enabled = NO;
    _chartView.legend.enabled = NO;
- (void)setData:(IBLAirGraphData *)data {
  _data = data;

  if (data.isEmpty) {
    return;
  }

  NSArray *xAxisTitles = [self xAxisTitles];
  NSMutableArray *yValues = [NSMutableArray array];

  NSArray *values = nil;

  switch (self.filterView.filterType) {
    case IBLAirGraphFilterTypeVOC:
      values = data.vocValues;
      break;

    case IBLAirGraphFilterTypeTemperature:
      values = data.temperatureValues;
      break;

    case IBLAirGraphFilterTypeHumidity:
      values = data.humidityValues;
      break;
  }

  [values enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    double value = [data isValidValue:obj] ? [obj doubleValue] : 0;
    [yValues addObject:[[ChartDataEntry alloc] initWithValue:value xIndex:idx]];
  }];

  LineChartDataSet *dataSet = (LineChartDataSet *)self.chartView.data.dataSets.firstObject;

  if (!dataSet) {
    dataSet = [[LineChartDataSet alloc] initWithYVals:yValues];
  }

  dataSet.drawFilledEnabled = YES;
  dataSet.drawHorizontalHighlightIndicatorEnabled = NO;
  dataSet.drawVerticalHighlightIndicatorEnabled = NO;
  dataSet.drawCubicEnabled = YES;
  dataSet.lineWidth = 2.0;
  dataSet.circleRadius = 2.0;
  dataSet.valueFormatter = self.valueFormatter;
  dataSet.valueFont = [UIFont systemFontOfSize:9.f];
  dataSet.valueTextColor = [UIColor ibl_colorWithRed:255 green:129 blue:98];
  [dataSet setColor:[UIColor ibl_colorWithRed:255 green:139 blue:110]];

  self.chartView.data.xValsObjc = xAxisTitles;
  self.chartView.data = [[LineChartData alloc] initWithXVals:xAxisTitles dataSets:@[dataSet]];
  [self.chartView animateWithXAxisDuration:1 easingOption:ChartEasingOptionEaseInOutQuart];
}

Any help will be appreciated.

@VincentSit
Copy link
Contributor Author

Sloved by adding _chartView.leftAxis.axisMinValue = 0;

But I still don't know how to skip value.

image

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 11, 2016

use .horizontalBezier enum in LineChartDataSet to solve the cubic issue.

@VincentSit
Copy link
Contributor Author

@liuxuan30

Thanks. Do you know how to to skip value? I've searched and found some relevant issue, but don't know how to do.

@liuxuan30
Copy link
Member

@VincentSit first, if you don't need value, just don't insert any entry for the xIndex, but xIndex should be there.
second, in line chart, currently, if you just don't insert entry, the line will connect to the next available value, so the line is still not broke, if you are asking this. #280 is not supported yet. But you can modify the code to suport line breaking (I have done that on my side, but it's kind of tricky, and I am still not having time how to do it in a right way)

@VincentSit
Copy link
Contributor Author

@liuxuan30 I think I see what you mean now, thank you.

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

2 participants