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

Not able to plot values in linechart #2349

Closed
anickt opened this issue Apr 11, 2017 · 13 comments
Closed

Not able to plot values in linechart #2349

anickt opened this issue Apr 11, 2017 · 13 comments

Comments

@anickt
Copy link

anickt commented Apr 11, 2017

I have added my issue on stack overflow please check the link

@anickt anickt changed the title Not able to plot the values Not able to plot values in linechart Apr 11, 2017
@liuxuan30
Copy link
Member

Would you please debug on your side? As the line starts turning around, there is no obvious reason to not draw the last 6 value pairs, you can first add some breakpoints at drawDataSets in line chart renderer, to see if all your missing values are there, and if the loop condition mets.

@anickt
Copy link
Author

anickt commented Apr 13, 2017

In data set I am getting all values see below:

ChartDataEntry, x: 0.0, y 0.62020133693747
ChartDataEntry, x: 0.0, y 0.62020133693747
ChartDataEntry, x: 0.0, y 0.62020133693747
ChartDataEntry, x: 8500.0, y 0.62020133693747
ChartDataEntry, x: 8500.0, y 0.925703706122449
ChartDataEntry, x: 9000.0, y 0.925703706122449
ChartDataEntry, x: 9000.0, y 1.43307403327373
ChartDataEntry, x: 9500.0, y 1.43307403327373
ChartDataEntry, x: 9500.0, y 0.37799568
ChartDataEntry, x: 9500.0, y 0.37799568
ChartDataEntry, x: 9500.0, y 0.37799568
ChartDataEntry, x: 9000.0, y 0.37799568
ChartDataEntry, x: 9000.0, y 0.269996914285714
ChartDataEntry, x: 8500.0, y 0.269996914285714
ChartDataEntry, x: 8500.0, y 0.239997257142857
ChartDataEntry, x: 6000.0, y 0.239997257142857
ChartDataEntry, x: 6000.0, y 0.219552079597251
ChartDataEntry, x: 0.0, y 0.219552079597251
ChartDataEntry, x: 0.0, y 0.453594816
ChartDataEntry, x: 0.0, y 0.453594816

@anickt
Copy link
Author

anickt commented Apr 13, 2017

Can you try to plot this value in line-chart from your end?

@liuxuan30
Copy link
Member

I don't have time to put them in the demo yet. You can try first. Have you checked what I said?

@thierryH91200
Copy link
Contributor

the problem is here

in BarLineScatterCandleBubbleRenderer

open class XBounds
  {
      /// minimum visible entry index
      open var min: Int = 0

      /// maximum visible entry index
      open var max: Int = 0

      /// range of visible entry indices
      open var range: Int = 0

      public init()
      {
          
      }
      
      public init(chart: BarLineScatterCandleBubbleChartDataProvider,
                  dataSet: IBarLineScatterCandleBubbleChartDataSet,
                  animator: Animator?)
      {
          self.set(chart: chart, dataSet: dataSet, animator: animator)
      }
      
      /// Calculates the minimum and maximum x values as well as the range between them.
      open func set(chart: BarLineScatterCandleBubbleChartDataProvider,
                    dataSet: IBarLineScatterCandleBubbleChartDataSet,
                    animator: Animator?)
      {
          let phaseX = Swift.max(0.0, Swift.min(1.0, animator?.phaseX ?? 1.0))
          
          let low = chart.lowestVisibleX
          let high = chart.highestVisibleX
          
          let entryFrom = dataSet.entryForXValue(low, closestToY: Double.nan, rounding: ChartDataSetRounding.down)
          let entryTo = dataSet.entryForXValue(high, closestToY: Double.nan, rounding: ChartDataSetRounding.up)
          
          self.min = entryFrom == nil ? 0 : dataSet.entryIndex(entry: entryFrom!)
          self.max = entryTo == nil ? 0 : dataSet.entryIndex(entry: entryTo!)
//          self.max = 20
          range = Int(Double(self.max - self.min) * phaseX)
      }
  }

add the last line

self.max = 20

capture d ecran 2017-04-14 a 12 44 25

@anickt
Copy link
Author

anickt commented Apr 14, 2017

Hey @liuxuan30 I tried what you said. I am getting all 20 values in data-set.
and @thierryH91200 when I added that line it was crashing the app.

@thierryH91200
Copy link
Contributor

change the value to 18

@anickt
Copy link
Author

anickt commented Apr 14, 2017

Yes It Works. But this is not an ideal solution. How can I set this value from outside of the library?

@thierryH91200
Copy link
Contributor

let tab = [[0.0, 0.62020133693747],
           [0.0, 0.62020133693747],
           [0.0, 0.62020133693747],
           [8500.0, 0.62020133693747],
           [8500.0,  0.925703706122449],
           [ 9000.0,  0.925703706122449],
           [ 9000.0,  1.43307403327373],
           [ 9500.0,  1.43307403327373],
           [ 9500.0,  0.37799568],
           [ 9500.0,  0.37799568],
           [ 9500.0,  0.37799568],
           [ 9000.0,  0.37799568],
           [ 9000.0,  0.269996914285714],
           [ 8500.0,  0.269996914285714],
           [ 8500.0,  0.239997257142857],
           [ 6000.0,  0.239997257142857],
           [ 6000.0,  0.219552079597251],
           [ 0.0,  0.219552079597251],
           [ 0.0,  0.453594816],
           [  0.0,  0.453594816]]


for i in 0..<tab.count {
    let x = tab[i][0]
    let y = tab[i][1]
    yVals1.append(ChartDataEntry(x: x, y: y))
}

print( tab.count)

set1 = LineChartDataSet(values: yVals1, label: "DataSet 1")
set1.axisDependency = .left

var dataSets = [LineChartDataSet]()
dataSets.append(set1)
let data = LineChartData(dataSets: dataSets)
chartView.data = data

for me it is good

remove UIImage ....

Try the simplest

@liuxuan30
Copy link
Member

@thierryH91200 are you suggesting entryTo has bug?
I don't know why set self.max = 18

@anickt
Copy link
Author

anickt commented Apr 19, 2017

Yes even I don't understand

@thierryH91200
Copy link
Contributor

it's not really a bug

 /// Calculates the minimum and maximum x values as well as the range between them.
      open func set(chart: BarLineScatterCandleBubbleChartDataProvider,
                    dataSet: IBarLineScatterCandleBubbleChartDataSet,
                    animator: Animator?)
      {

Charts does not like too much backwards in time on the OX axis
The simplest is to create 2 increasing datasets that meet

max = 18 or 20 this is the same thing = tab.count => values duplicates

let tab1 = [[0.0, 0.62020133693747],
           [0.0, 0.62020133693747],
           [0.0, 0.62020133693747],
           [8500.0, 0.62020133693747],
           [8500.0,  0.925703706122449],
           [ 9000.0,  0.925703706122449],
           [ 9000.0,  1.43307403327373],
           [ 9500.0,  1.43307403327373],
           [ 9500.0,  0.37799568],
           [ 9500.0,  0.37799568],
           [ 9500.0,  0.37799568]]

let tab2=
           [[  0.0,  0.453594816]]
           [ 0.0,  0.453594816],
           [ 0.0,  0.219552079597251],
           [ 6000.0,  0.219552079597251],
           [ 6000.0,  0.239997257142857],
           [ 8500.0,  0.239997257142857],
           [ 8500.0,  0.269996914285714],
           [ 9000.0,  0.269996914285714],
           [ 9000.0,  0.37799568]]

or modify
open func set
this is dangerous

@liuxuan30
Copy link
Member

ok, thanks. Seems we can close this

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

3 participants