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 Chart do not draw line for Data Set #2567

Closed
kbilyk opened this issue Jun 28, 2017 · 14 comments
Closed

Line Chart do not draw line for Data Set #2567

kbilyk opened this issue Jun 28, 2017 · 14 comments

Comments

@kbilyk
Copy link

kbilyk commented Jun 28, 2017

I need to update draw line chart to display result of calculations.

For some reason for data set:
Charts.LineChartDataSet, 13 entries: ChartDataEntry, x: 450.479217529297, y 7217.4140625 ChartDataEntry, x: 450.068511962891, y 7090.0 ChartDataEntry, x: 449.577758789062, y 6932.0 ChartDataEntry, x: 449.156005859375, y 6774.0 ChartDataEntry, x: 450.691955566406, y 6616.0 ChartDataEntry, x: 453.031677246094, y 6458.0 ChartDataEntry, x: 455.456634521484, y 6300.0 ChartDataEntry, x: 455.092803955078, y 6142.0 ChartDataEntry, x: 454.658813476562, y 5984.0 ChartDataEntry, x: 454.492492675781, y 5905.0 ChartDataEntry, x: 454.336486816406, y 5668.0 ChartDataEntry, x: 454.281585693359, y 5589.0 ChartDataEntry, x: 454.243194580078, y 5510.0

Line can be drawn:
img_0081

And for data set:
Charts.LineChartDataSet, 13 entries: ChartDataEntry, x: 450.359344482422, y 7182.85095214844 ChartDataEntry, x: 450.068511962891, y 7090.0 ChartDataEntry, x: 449.577758789062, y 6932.0 ChartDataEntry, x: 449.156005859375, y 6774.0 ChartDataEntry, x: 450.691955566406, y 6616.0 ChartDataEntry, x: 453.031677246094, y 6458.0 ChartDataEntry, x: 455.456634521484, y 6300.0 ChartDataEntry, x: 455.092803955078, y 6142.0 ChartDataEntry, x: 454.658813476562, y 5984.0 ChartDataEntry, x: 454.492492675781, y 5905.0 ChartDataEntry, x: 454.336486816406, y 5668.0 ChartDataEntry, x: 454.281585693359, y 5589.0 ChartDataEntry, x: 454.243194580078, y 5510.0

It is no longer drawing:
img_0082

@liuxuan30
Copy link
Member

Are you able to debug on your side... I can say nothing...
Check how you update your line chart, and if the sets/entries are updated, and it redraw them in line chart renderer.

@kbilyk
Copy link
Author

kbilyk commented Jul 3, 2017

@liuxuan30 thank you for your suggestion.

Posted data sets are taken from LineChartDataSet graphDataSet instance on breakpoint right before calling notifyDataSetChanged:

screenshot 2017-07-03 14 53 03

And LineChartData instance chartData also contains LineChartDataSet graphDataSet with expected values:

screenshot 2017-07-03 14 58 26

I will deeper investigate if:

... it redraw them in line chart renderer

And will come back with more data.

Also I've experimented with ordering Data Sets by xValues and graph is redrawing perfectly with same code. But I need ChartDataEntries to be ordered as it is otherwise it is meaningless.

If you can suggest any other ideas where to look I would be really helpful.

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 4, 2017

OK, if you sure the data contains all your line data sets, when you debugging at
line chart renderer -> open func drawDataSet(context: CGContext, dataSet: ILineChartDataSet)

Normally, it will read all your sets and render them.

Giving the fact that in your first image it can render two lines already, I think the renderer should be fine. The problem is, the second time it tries drawing, the second line(red line) is missing, so you need to check does drawDataSet see them and draw?

I reviewed your two data set samples, they are the same, except for the first one, which only has very small difference. Is there anything wrong on your side? If they are the same, why redraw again?

BTW, you don't have to call notifyDataSetChanged() after chart.data = data, the data setter will call it for you. So performance gained.

@kbilyk
Copy link
Author

kbilyk commented Jul 4, 2017

@liuxuan30 once again thank you for replay.

BTW, you don't have to call notifyDataSetChanged() after chart.data = data, the data setter will call it for you. So performance gained.

I've noticed that in scope of debugging, thanks.

reviewed your two data set samples, they are the same, except for the first one, which only has very small difference. Is there anything wrong on your side? If they are the same, why redraw again?

It is a process of dynamic recalculation and redrawing when User changes input value using slider.

The problem is, the second time it tries drawing, the second line(red line) is missing, so you need to check does drawDataSet see them and draw?

I think I've found root of issue.

For some reason in drawLinear() before drawing xBounds recalculating with _xBounds.set(chart: dataProvider, dataSet: dataSet, animator: animator) and as result in cases when DataSets not drawing xBounds.range value is negative.

I'll investigate what causes that in _xBounds.set() and suggest fix if it is possible.

@kbilyk
Copy link
Author

kbilyk commented Jul 4, 2017

@liuxuan30 so in scope of mine investigation it appears that _xBounds.set() which is XBounds.set()calculated min, max and range of visible entry indices incorrectly for my case (when xValues are not ordered):

screenshot 2017-07-04 14 45 41

And later was incorrectly used in drawLinear() for getting stride():

screenshot 2017-07-04 14 51 23

What happened? _xBounds.set() found self.min as index = 11, self.max as index = 8 and range as -3. So later in stride() for positive begin and negative end we got nothing.

Code in library works correctly only for ordered xValues because in this case self.min = 0, self.max = dataSet.entryCount - 1 and range = dataSet.entryCount.

So all code in XBounds.set() can be replaced with:

self.max = dataSet.entryCount - 1
range = dataSet.entryCount

And it will cover case of not ordered xValues:

simulator screen shot jul 4 2017 15 03 37

Moreover let entryFrom = dataSet.entryForXValue(low, closestToY: Double.nan, rounding: ChartDataSetRounding.down) and let entryTo = dataSet.entryForXValue(high, closestToY: Double.nan, rounding: ChartDataSetRounding.up) does not compute correct entryFrom and entryTo for not ordered xValue case:

screenshot 2017-07-04 15 17 15

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 7, 2017

one thing is missing that, how do you update your data? e.g. do you use addEntryOrdered to add the new entries to keep it sorted?
I checked the code it seems that the library does not sort values itself. It assumes it' already sorted.

barriserloth added a commit to barriserloth/Charts that referenced this issue Jan 21, 2018
This commit fixes an issue brought up in ChartsOrg#2567
(ChartsOrg#2567), where
lines (and points) in LineCharts would not render correctly if the
x-values were not in order.
@jcamachov
Copy link

@kbilyk how do you create a blue line in the chart?, could you give me the sample code?. I have to do a chart with polygon with coordinates like your polygon (blue line) but I can't find the solution about this issue.

@kbilyk
Copy link
Author

kbilyk commented Apr 2, 2018

@jcamachov firs of all you need to replace content of function XBounds.set() with:

self.max = dataSet.entryCount - 1
range = dataSet.entryCount

This change will allow you to pass not ordered by X data set and Charts will draw every point.

Your data set should have first and last points with same coordinates in order to draw closed figure.

Hope this will help with your issue.

@jcamachov
Copy link

@kbilyk thank you for quick answer. What kind of chart must I use? LineChartView?, ScatterChartView?... I think that I use LineChartView but I can't change self.max and range in order to try that you say me in your answer.

@kbilyk
Copy link
Author

kbilyk commented Apr 2, 2018

@jcamachov I've used LineChartView.

I can't change self.max and range

You'd, probably, should fork repo or make it local pod (as I did).

@hungcaobss
Copy link

@kbilyk : I changed XBounds.set() as you suggested, line chart is ok but I can not tap on it to highlight for some values. Do you have any solution?

@purevdorjsodnomdorj
Copy link

set 1 -> screen shot 2018-10-30 at 11 36 57 am
LineChartData *data = [[LineChartData alloc] initWithDataSets:@[set1]];
but data initialized data is empty, draw nothing

@PeterKaminski09
Copy link
Contributor

I'm running into a similar issue where I have a set of scatter chart data points, and the first data point isn't having it's custom icon rendered.

Here is the issue I'm seeing

...
for j in _xBounds {
    guard let e = dataSet.entryForIndex(j) else { break }               
    ...
}

This loop in ScatterChartRenderer is only running from 1 to dataSet.entryCount - 1.

public mutating func next() -> Int? {
     guard value < bounds.max else { return  nil }
     value += 1
     return value
}

It seems like the iterator for xBounds increments value to 1 before it is returned, so the 0th element is never being iterated over and rendered.

This is for version 3.2.2 as we have yet to upgrade to swift 5.

@PeterKaminski09
Copy link
Contributor

Ahh I see this ☝️has been fixed in 3.3.0. 🎉

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

6 participants