-
-
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
Grouped columns misplaced #242
Comments
I've found out that adding another BarChartData for different x-cooridnate creates this Data for other indexes as well... that's why everything is moved by some offset, but I have not idea how fix it. Data: BarChartDataSet *set = [[BarChartDataSet alloc] initWithYVals:@[entry] label:@"tst"]; BarChartDataEntry *entry4 = [[BarChartDataEntry alloc] initWithValues:@[@4] xIndex:2]; NSArray *tstArr = @[set,set2, set4]; BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:tstArr]; Produces this (note the "highlighted column that shouldn't even exist for that index): |
Did you add the xIndexes? |
Yes, there are 3 x-indexes (timestamps) |
You need to attach a screenshot or a working sample project |
Ok, while using HorizontalBarChartView and using this array as a X-data: and this as a dataSets: BarChartDataEntry *entry3 = [[BarChartDataEntry alloc] initWithValues:@[@6] xIndex:1]; NSArray *tstArr = @[set,set2,set3,set4]; BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:tstArr]; Produces this graph, (note the "selected" gray column with value 1, which shouldn't exist for that index): http://imgur.com/Cmt0QtM |
It seems to be a highlight bug, when the x axis is reversed. @PhilJay did you notice this? |
I updated the library, (changed x-values to array ("1","2","3"). Placement of bars is wrong, however now it doesn't repeat the values (I can only "highlight" 6 and 7 bars in "2" index as shown on screenshot - http://imgur.com/J2qEM47). |
@danielgindi though I don't fully understand this issue, but it sounds like it is related to issue #214? I got a PR for it. BTW, I don't see the x axis is reversed? @JanciP, if possible that you are familiar with the code, can you try if #221 fix your issue? |
@liuxuan30 I'm not very familiar with the code, however I looked at your files and modified mine accordingly but the issue is still present. Bars are still drawn at wrong place. I've tried adding datas for every x-value. This is what it looks like : with #221 implemented http://imgur.com/2bdCjsb |
Try to invert the xaxis see if it still happens On Mon, Jul 27, 2015 at 12:30 PM, JanciP notifications@github.com wrote:
|
@danielgindi you mean using barchart class instead of horizontal bar chart? |
No, I mean setting "inverted" on the axis
|
With leftAxis.inverted = YES; it still unfortunately happens :( (ChartYAxis *leftAxis = self.chart.leftAxis;) |
@danielgindi I think I can confirm it is same issue as #214, only that I am dealing with bar chart, but this is horizontal bar chart, which I don't change yet. It is reproducible on bar chart and horizontal bar chart with same dataSets. @JanciP do you change the horizontal bar chart code like mine, not in bar chart code? It should take effect. Anyway, I have pushed code for horizontal bar chart at #221 . Please try it. Make sure you change the correct file for horizontal bar chart. After I apply my potential fix, I got the screenshot, it seems render and highlight OK, but I am guessing shouldn't the bars be center aligned in their x axis zone? I touched nothing about the alignment. dataSet code: - (void)setDataCount:(int)count range:(double)range
{
NSMutableArray *xVals = [[NSMutableArray alloc] init];
xVals = @[@"jan",@"feb",@"mar"];
BarChartDataEntry *entry = [[BarChartDataEntry alloc] initWithValue:1 xIndex:0];
BarChartDataEntry *entry2 = [[BarChartDataEntry alloc] initWithValue:4 xIndex:0];
BarChartDataSet *set = [[BarChartDataSet alloc] initWithYVals:@[entry] label:@"test1"];
BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:@[entry2] label:@"test2"];
BarChartDataEntry *entry3 = [[BarChartDataEntry alloc] initWithValues:@[@6] xIndex:1];
BarChartDataEntry *entry4 = [[BarChartDataEntry alloc] initWithValues:@[@7] xIndex:1];
BarChartDataSet *set3 = [[BarChartDataSet alloc] initWithYVals:@[entry3] label:@"test3"];
BarChartDataSet *set4 = [[BarChartDataSet alloc] initWithYVals:@[entry4] label:@"test4"];
NSArray *tstArr = @[set,set2,set3,set4];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:tstArr];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
_chartView.data = data;
} |
Alright I figured out the alignment problem. @JanciP, I am not sure if it is your issue or the ios-chart duty to handle, but if there are two bars in one group, there should be only two dataSets, not 4, and each dataSet has two dataEntries. What you are using has 4 dataSets, and it leads to more space left for each x axis zone, that's why it is not centered. Try below code: NSMutableArray *xVals = [[NSMutableArray alloc] init];
xVals = @[@"jan",@"feb", @"mar"];
BarChartDataEntry *entry = [[BarChartDataEntry alloc] initWithValue:1 xIndex:0];
BarChartDataEntry *entry2 = [[BarChartDataEntry alloc] initWithValue:4 xIndex:0];
BarChartDataEntry *entry3 = [[BarChartDataEntry alloc] initWithValue:6 xIndex:1];
BarChartDataEntry *entry4 = [[BarChartDataEntry alloc] initWithValue:7 xIndex:1];
BarChartDataSet *set = [[BarChartDataSet alloc] initWithYVals:@[entry,entry3] label:@"test1"];
BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:@[entry2,entry4] label:@"test2"];
// BarChartDataSet *set3 = [[BarChartDataSet alloc] initWithYVals:@[entry3] label:@"test3"];
// BarChartDataSet *set4 = [[BarChartDataSet alloc] initWithYVals:@[entry4] label:@"test4"];
NSArray *tstArr = @[set,set2];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:tstArr];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
_chartView.data = data; Screen shot on my side based on #221 |
Yes that's definitely a problem with your code
|
about the alignment, I think it's @JanciP problem. but for the position, it's ours. I think I broke my PR by merging from upstream master... I will try figure a way later. |
What do you mean by position? The new screenshot looks good |
@danielgindi take a look at #214 , same issue for bar+horizontal bar chart. I got PR #221 for it. It renders the bars at wrong position, if some xIndex don't have entries. To be exact, the xValsCount is not equal to entryCount in each dataSet. This will lead to wrong position. Very simple to reproduce... just paste the above dataSet code to the chart demo, you will see wrong position and wrong highlight... |
Well the code above looks good, with a valid screenshot. I think you are referring to the code in the other issue? |
This is the test dataSet code I used before, it render at wrong position and highlight for second group is failed. NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < 11; i++)
{
[xVals addObject:[@(i + 2015) stringValue]];
}
NSMutableArray *yVals1 = [[NSMutableArray alloc] init];
NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
for (int i = 0; i < 11; i++)
{
if (i == 0) {
[yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:2354235 xIndex:i]];
[yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:3354235 xIndex:i]];
} else if (i == 10) {
[yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:6354235 xIndex:i]];
[yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:7354235 xIndex:i]];
} else {
continue;
}
}
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals1 label:@"Company A"];
[set1 setColor:[UIColor colorWithRed:104/255.f green:241/255.f blue:175/255.f alpha:1.f]];
BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:yVals2 label:@"Company B"];
[set2 setColor:[UIColor colorWithRed:164/255.f green:228/255.f blue:251/255.f alpha:1.f]];
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
[dataSets addObject:set2];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
data.groupSpace = 0.8;
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
_chartView.leftAxis.startAtZeroEnabled = NO;
_chartView.rightAxis.startAtZeroEnabled = NO;
_chartView.data = data; just replace it in multiple bar chart view controller. |
@liuxuan30 agree, with your #221 code and advice you provided in last post, it seems to be working. Thank you! |
@JanciP you are welcome! @danielgindi NSMutableArray *xVals = [[NSMutableArray alloc] init];
xVals = @[@"jan",@"feb", @"mar"];
BarChartDataEntry *entry = [[BarChartDataEntry alloc] initWithValue:1 xIndex:0];
BarChartDataEntry *entry2 = [[BarChartDataEntry alloc] initWithValue:4 xIndex:0];
BarChartDataEntry *entry3 = [[BarChartDataEntry alloc] initWithValue:6 xIndex:2]; // not 1
BarChartDataEntry *entry4 = [[BarChartDataEntry alloc] initWithValue:7 xIndex:2]; // not 1
BarChartDataSet *set = [[BarChartDataSet alloc] initWithYVals:@[entry,entry3] label:@"test1"];
BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:@[entry2,entry4] label:@"test2"];
// BarChartDataSet *set3 = [[BarChartDataSet alloc] initWithYVals:@[entry3] label:@"test3"];
// BarChartDataSet *set4 = [[BarChartDataSet alloc] initWithYVals:@[entry4] label:@"test4"];
NSArray *tstArr = @[set,set2];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:tstArr];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
_chartView.data = data; |
@liuxuan30 based on your code I was able to display graph correctly. But is it also possible to have different number of DataEntries for each data set? Lets say for x: |
I will have to test this on Android, gimme a sec. |
Some words beforehand:
|
@PhilJay I know little about Java+android, but based on the commit, looks like we share the same idea to fix. @danielgindi I am not sure If I missed anything somewhere. Please review |
Ok so having same amount of objects(y-vals) for each BarDataSet works very well now (as proven by @PhilJay). My question is, would chart display correctly if we are tracking irregular occurences (that means that BarDataSets won't contain same amount of objects? Code wise I mean something like this ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
yVals1.add(new BarEntry(1f, 0));
yVals1.add(new BarEntry(2f, 1));
//no yval for x==2
yVals1.add(new BarEntry(4f, 3));
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
yVals2.add(new BarEntry(5f, 0));
//no yvals for x== 1,2,3
ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
yVals3.add(new BarEntry(9f, 0));
yVals3.add(new BarEntry(10f, 1));
yVals3.add(new BarEntry(11f, 2));
yVals3.add(new BarEntry(12f, 3)); |
can you try the code and give screenshot? I think it should work. Make sure you have 3 dataSets |
Current scheme does not support this. the distance on xAxis is equal. If you are asking making the xAxis not equal distance, It sounds like what you are asking is like #176 and #194. For the case you mentioned, I think current bar chart is more meaningful, if we squash all the gaps there, it seems not very easy to understand as bar chart. Bar chart has the nature to let people compare among the bars. |
Ok @liuxuan30 I undestand, thank you very much for your help. I learned a lot from your posts. Thanks! |
Hey, I'm having troubles with grouped bar chart.
My barChartData are following:
x-values (array of dates):
02.júla.15,
23.júla.15,
24.júla.15
dataSets:
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 0, value 0.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 0, value 0.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 0, value 0.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 0, value 0.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 0, value 0.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 1, value 39.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 2, value 16.0,
ChartDataSet, label: tst, 1 entries:
ChartDataEntry, xIndex: 2, value 28.0
This produces almost correct result, however bars seems to have wrong position as showed in this image http://imgur.com/Vq43QFH
What am I doing wrong? :)
The text was updated successfully, but these errors were encountered: