-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Different line width #1204
Comments
semms the top line is clipped. it seems your y axis range is just mapped to the whole contentRect, so drawing on the top edge causes clipping. I assume you have set axisMaxValue. By default, the range will slighly largher than 1, giving some space to draw the line. I think there is no quick solution here, because you are drawing on the edge with clipping enabled, and line width is larger than 1 |
I set the line chart in these two functions. - (void)setupLineChartView {
// Disable all interactions
self.lineChartView.dragEnabled = NO;
self.lineChartView.pinchZoomEnabled = NO;
[self.lineChartView setScaleEnabled:NO];
self.lineChartView.highlightPerTapEnabled = NO;
self.lineChartView.highlightPerDragEnabled = NO;
self.lineChartView.doubleTapToZoomEnabled = NO;
self.lineChartView.borderLineWidth = 5.0;
self.lineChartView.descriptionText = @"";
// Legend
self.lineChartView.legend.enabled = NO;
// X axis
self.lineChartView.xAxis.labelPosition = XAxisLabelPositionBottom;
self.lineChartView.xAxis.drawGridLinesEnabled = NO;
self.lineChartView.xAxis.labelFont = [UIFont systemFontOfSize:11.0 weight:UIFontWeightRegular];
self.lineChartView.xAxis.labelTextColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
self.lineChartView.xAxis.spaceBetweenLabels = 1;
self.lineChartView.xAxis.avoidFirstLastClippingEnabled = YES;
// Y axis
self.lineChartView.rightAxis.enabled = NO;
self.lineChartView.leftAxis.labelFont = [UIFont systemFontOfSize:12.5 weight:UIFontWeightSemibold];
self.lineChartView.leftAxis.labelTextColor = [UIColor colorWithRed:151/255.0 green:151/255.0 blue:151/255.0 alpha:1.0];
self.lineChartView.leftAxis.gridColor = [UIColor colorWithRed:151/255.0 green:151/255.0 blue:151/255.0 alpha:1.0];
self.lineChartView.leftAxis.drawAxisLineEnabled = NO;
[self.lineChartView.leftAxis setLabelCount:5 force:YES];
self.lineChartView.leftAxis.granularity = 0.25;
self.lineChartView.leftAxis.granularityEnabled = YES;
self.lineChartView.leftAxis.drawZeroLineEnabled = NO;
self.lineChartView.leftAxis.axisMinValue = 0.0;
self.lineChartView.leftAxis.axisMaxValue = 1.0;
NSNumberFormatter *percentFormatter = [[NSNumberFormatter alloc] init];
percentFormatter.numberStyle = NSNumberFormatterPercentStyle;
percentFormatter.roundingMode = NSNumberFormatterRoundFloor;
self.lineChartView.leftAxis.valueFormatter = percentFormatter;
self.lineChartView.minOffset = 20.0;
} - (void)adjustLineChartWithKpiArray:(NSArray<NSNumber *> *)kpiArray {
// Create data set
NSMutableArray<ChartDataEntry *> *yVals = [NSMutableArray array];
BOOL containsAllNoData = YES;
for (NSInteger i=1; i<=[kpiArray count]; i++) {
NSNumber *kpiNumber = kpiArray[i-1];
if (![kpiNumber isEqual:[NSNull null]]) {
containsAllNoData = NO;
}
BOOL noData = [kpiNumber isEqual:[NSNull null]];
float kpi = noData ? 0.0f : [kpiNumber floatValue];
ChartDataEntry *chartDataEntry = [[ChartDataEntry alloc] initWithValue:kpi xIndex:i];
[yVals addObject:chartDataEntry];
}
if (!containsAllNoData) {
// This check is make sure that entries can be
// [ 0.0, 0.0, 0.0, 0.0, 0.0 ] or [ 0.0, 0.8, 0.3, 0.5 ] but not [ 0.0, 1.0, 0.0, 0.0 ]
// remove all 0.0 behind positive value
//
for (NSInteger i = [kpiArray count]-1; i >= 0; i--) {
BOOL hasData = ![kpiArray[i] isEqual:[NSNull null]];
if (hasData) {
break;
}
[yVals removeObjectAtIndex:i];
}
}
LineChartDataSet *dataSet = [[LineChartDataSet alloc] initWithYVals:yVals label:@"engagement data set"];
dataSet.axisDependency = AxisDependencyLeft;
dataSet.drawCircleHoleEnabled = NO;
dataSet.circleRadius = 5.0;
dataSet.drawValuesEnabled = YES;
NSNumberFormatter *dataSetformatter = [[NSNumberFormatter alloc] init];
dataSetformatter.numberStyle = NSNumberFormatterPercentStyle;
dataSetformatter.roundingMode = NSNumberFormatterRoundFloor;
dataSet.valueFormatter = dataSetformatter;
// Create line colors
NSMutableArray<UIColor *> *lineColors = [NSMutableArray array];
for (NSInteger i=1; i<[kpiArray count]; i++) {
NSNumber *previousDayKPI = kpiArray[i-1];
NSNumber *currentDayKPI = kpiArray[i];
BOOL noPreviousData = [previousDayKPI isEqual:[NSNull null]];
BOOL noCurrentData = [currentDayKPI isEqual:[NSNull null]];
if (noPreviousData || noCurrentData) {
[lineColors addObject:[UIColor clearColor]];
} else {
[lineColors addObject:[UIColor ekoThemeColor]];
}
}
// Create circle colors and value colors
NSMutableArray<UIColor*> *circleColors = [NSMutableArray array];
NSMutableArray<UIColor*> *valueColors = [NSMutableArray array];
for (NSNumber *kpiNumber in kpiArray) {
BOOL noData = [kpiNumber isEqual:[NSNull null]];
UIColor *circleColor = noData ? [UIColor ekoGrayColor] : [UIColor ekoThemeColor];
[circleColors addObject:circleColor];
[valueColors addObject:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]];
}
dataSet.valueColors = valueColors;
dataSet.colors = lineColors;
dataSet.circleColors = circleColors;
dataSet.lineWidth = 1.0f;
// Create data
NSArray<NSString *> *xVals = @[@"", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @""];
LineChartData *lineData = [[LineChartData alloc] initWithXVals:xVals dataSet:dataSet];
self.lineChartView.data = lineData;
} |
yes I see you have specified axisMaxValue, which will force the edge to be exactly at "100%". As I said earlier, I think there is no quick solution here, because you are drawing on the edge with clipping enabled, and line width is no less than 1 |
one thing could be improved is, counting the half max line width (among axis line, grid line, data set line) into account, so increase the contentRect to have enough space for lines on the edge |
Now there is no way to fix right ? |
I think it can be fixed as I mentioned above, but we don't have enough man power to do so right now. I want to help but a lots of things on my plate right now, so maybe later. |
@danielgindi Is there gonna be a release with this fix (cocoapods version)? |
migrate Chart v3 code in master to swift 2.3 syntax (#1387) * upgrade carthage to 0.17.1 * use master commit for iso-snapshot-test-case for now. once the fix is tagged we could change to the new version * change Rakefile, comment out tvOS because no FBSnapshotTestCase * Add missing imports for iOS 7 support * Update ChartSelectionDetail.swift * BUGFIX: fix infinite recursive call of getXIndex(_:) * for #1208, seems drawBarShadowEnabled should be false by default * 1. update ios-snapshot-test-case to 2.1.2 2. remove brew upgrade carthage, because travis saying * improve descriptions to warn users how to use setVisibleRange APIs * Typo fix * upgrade Realm to 1.0.2 * update Realm pod spec to 1.0.2 * fix pod spec typo * Work on x-values instead of x-indices (free for all :-) * Improvement for pie slice spacing calculation * Example improvements * Docs improvements * Major work on highlights * ChartMarker is now a protocol, and we have ChartMarkerView/Image helpers * Improvements regarding irrelevant inherited methods * Added feature to change color of "no data" text * More work on highlights * Viewport enhancements for better horizontal bar support * X-axis renderer enhancements for better horizontal bar support * Minor improvement to valueFormatter * Completed copy routine for scatter dataset * Pie: Renamed `drawSliceTextEnabled` to `drawEntryLabelsEnabled` * Pie: Added feature to offset center text * Pie: Separate color/font for entry labels (defaults to value color/font) * Minor improvements to demo * Minor refactoring of variable names * Example cleanup * Refactored scatter shape rendering into interface and renderers * Improved docs * Removed deprecated --var / var-- * Update README.md * Dropped iOS 7.0 support from README (Closes #601) * Fixed a RadarChart bug where value labels were misplaced * Realm fixes * Improvements to zoom methods * Legend improvements * DRYed some code * Adjusted maxHighlightDistance defaults * Removed NaN check for highlight. * Cleanup these comments * `drawBarShadowEnabled` is working again * Do not invalidate here by default, like other zoom methods * Simplified scatter shape enum model * These return a single pixel (x/y), for values (x value and y value) * Renamed x-pos to x-value where appropriate * Renamed ChartMarker -> IChartMarker * Namespace `Marker` names only for Objc (Swift 2.2) The Charts v3 changes are a chance to do this, as it's a breaking change anyway. * Do not force unwrap here * Fix for comments * More improvements to Markers, default behaviour constraint to view size * Docs * The highlight breaking changes are a chance to use @objc(name) feature * Use @objc(name) feature for rarely used classes (by users) * Improved entryIndex rounding method * Fixed drawing bounds for some of the charts * Removed unused yValueForXValue / yValuesForXValue * Set a default shape renderer * Take the correct barData object here * Fixed combined chart highlight with bar data * Minor refactoring * Removed the extra offset that messed up legend location * Cache XBounds object * Breaking change: `valueFormatter` now accepts an IValueFormatter This allows for formatting depending on viewport state etc. * Avoid x values in Pie's calcMinMax * This workaround is not required in the newer compilers * Renamed formatter interfaces FillFormatter -> IFillFormatter ValueFormatter -> IValueFormatter AxisValueFormatter -> IAxisValueFormatter * Avoid truncating using Int(...), it overflows * Corrected formula for 29-feb :-) * Some minor bug fixes for formatters * Polished demos * More improvements to examples * These should be internal * Fixed xAxis min/max calculation typo * Added helper to generate a fill formatter with a closure (block) * Added more samples * Updated tests * Set default barWidth to match old default behaviour * Renamed axisMinValue/axisMaxValue to axisMinimum/axisMaximum * Cleaned up header comments (I know that most of these files were created by me, I don't need that in the headers...) * Removed deprecated startAtZero properties * When only one of scaleXEnabled or scaleYEnabled is effective * Docs * Cleanup * Use EPSILON instead of an arbitrary value (Fixes #1239) * Fix dataset update in Dual line chart demo (Fixes #1250) * Add half line width to clipping rect of grid/limit lines (Fixes #1204) * Simplified legend entries configuration. Option to style dataset form. (Closes #1282) * Added feature for dashing legend line forms * Change default formLineWidth to match the default on MPAndroidChart * neededWidth should be enough here. formSize has no meaning globally. If more offset is needed - use extraOffsets, or adjust the maxSizePercent). * Renamed those classes too. Cleaner now. Should be too breaking... As with swift's minimal syntax - the chance of anyone referencing those by name is very low. On ObjC, the names stayed the same, for namespacing. * Take care of edge cases when calculating intervals (labelCount == 0) * autoScaleMinMax is working again (Fixes #1209) * Minor refactoring (Closes #1187) Sorry, un-mergable to `master`... * Fixed reversed condition from cbd7bf7 * It's clearer this way * Fill before stroke - because the fill may cover half of a thick stroke (Closes #982) * Added those new classes to tvOS/macOS targets * Migrated viewFromXib to macOS * Call `print` under `Swift` namespace, due to Cocoa ambiguity in NSView * Migrated macOS demos to Charts 3.0 * Use an optional for _displayLink (Fixes #1336) _displayLink might not have been created, i.e. in Interface Builder context. * Corrected LineChartRenderer cubicFill x range * Fixed horizontal cubic calculation bug introduced when removing x-index * Avoid using deprecated property in demo * Updated test screenshots * Animating the wrong axis for the starting point * migrate Chart v3 code in master to swift 2.3 syntax
Have you guys fix this? I still have this issue in |
It's fixed in Aug 14. I checked the 3.0 code, it's there. |
Yeah. I still can reproduce. I changed the code in
for (int i = 0; i < 7; i++)
{
double val = (i % 3 == 0) ? 160 : 200.0;
[values addObject:[[ChartDataEntry alloc] initWithX:i y:val]];
}
// set1.lineDashLengths = @[@5.f, @2.5f];
// set1.highlightLineDashLengths = @[@5.f, @2.5f];
set1.lineWidth = 5.0; |
How to hide bottom info?? |
Is this issue resolve because i have suffer from same issue. can i get update? |
1 similar comment
Is this issue resolve because i have suffer from same issue. can i get update? |
I am still having this issue and found a good enough fix. Go to one or both of: And comment out the line "context.clip(to: self.gridClippingRect)" I'm not sure what unintended consequences this has, but I haven't noticed anything not working. |
I use line chart graph. Line width at 100% is thinner than others. Please help me. Thank you.
The text was updated successfully, but these errors were encountered: