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

TableView does not scroll vertically after graph is rendered to cells #2757

Closed
ikyh opened this issue Aug 29, 2017 · 2 comments
Closed

TableView does not scroll vertically after graph is rendered to cells #2757

ikyh opened this issue Aug 29, 2017 · 2 comments

Comments

@ikyh
Copy link

ikyh commented Aug 29, 2017

Hello..! Thank you for this wonderful and useful library. I want to plot live data on the graph.
I have referred to the solution of this issue (#754)
and have rendered graph to tableView.
Problem is:

  1. I can scroll the tableView vertically before maxXRange data of open func setVisibleXRange(minXRange: Double, maxXRange: Double) is set to the graphView . After the
    max range is attended the graph starts scrolling automatically to the left side.
  2. If I try to scroll the tableView vertically downwards, the graph gets scrolled to the right
    side(backwards) instead but the tableView does not scroll.
  3. Also the graph stops moving when I click on any other UI or while scrolling(scrolls when user
    touches the padding spaces to scroll up or down).

I have done this so far:

class TableGraphViewCells: UITableViewCell, ChartViewDelegate {
  @IBOutlet weak var graphView: LineChartView!

  override func awakeFromNib() {
    super.awakeFromNib()
    graphView.delegate = self
    let graphData: LineChartDataSet = LineChartDataSet(values: [ChartDataEntry(x: Double(0), y: Double(0))], label: "")
    graphData.drawCirclesEnabled = false
    graphData.setColors(UIColor.cyan)
    graphData.mode = LineChartDataSet.Mode.cubicBezier
    graphData.lineWidth = 2
    graphData.drawVerticalHighlightIndicatorEnabled = false
    graphData.drawHorizontalHighlightIndicatorEnabled = false   
 
    self.graphView.data = LineChartData(dataSets: [graphData])
    let timer = Timer.scheduledTimer(timeInterval: 0.20, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
}

// add point
var i = 0
func updateCounter() {
    let degrees: Double = (Double(arc4random_uniform(2)) * 2 - 1) * Double(arc4random_uniform(4))
    self.graphView.data?.addEntry(ChartDataEntry(x: Double(i), y: (degrees)), dataSetIndex: 0)
    self.graphView.setVisibleXRange(minXRange: Double(CGFloat(1)), maxXRange: Double(CGFloat(50)))
    self.graphView.notifyDataSetChanged()
    self.graphView.moveViewToX(Double(CGFloat(i)))
    self.graphView.legend.enabled = false
    self.graphView.doubleTapToZoomEnabled = false
    i = i + 1
}}

I have shown 10 graph cell rows in the table. Even though I have hidden the legend, it still appears only for 6th row initially and after I scroll, legend disappears and graph starts plotting the points. It happens only for 6th row. For 5 visible rows on the screens it works fine, but when I scroll to see next 5 rows for 6th row this happens. tableView.realodData() does not work. Graph is not rendered to tableView. here (Image appears to be rotated)
img_0061

Also I don't want to see the values of graph plotted on it. I tried to fix this but couldn't
3

I want to plot different graph for different cells with different colours.
What I get:
1

Expected Output :
2

Help or suggestions appreciated. Thanks :)

@ikyh ikyh changed the title TableView does not scroll vertically after maxXRange data is rendered to graph. TableView does not scroll vertically after data upto maxXRange is rendered to graph. Aug 29, 2017
@ikyh ikyh changed the title TableView does not scroll vertically after data upto maxXRange is rendered to graph. TableView does not scroll vertically after graph is rendered to cells Aug 30, 2017
@liuxuan30
Copy link
Member

liuxuan30 commented Sep 5, 2017

that's because we disabled it. you can disable dragEnabled. Details are within panGestureRecognized(_ recognizer: NSUIPanGestureRecognizer)

            if self.isDragEnabled &&
                (!self.hasNoDragOffset || !self.isFullyZoomedOut)
            {
                _isDragging = true
                
                _closestDataSetToTouch = getDataSetByTouchPoint(point: recognizer.nsuiLocationOfTouch(0, inView: self))
                
                let translation = recognizer.translation(in: self)
                let didUserDrag = (self is HorizontalBarChartView) ? translation.y != 0.0 : translation.x != 0.0
                
                // Check to see if user dragged at all and if so, can the chart be dragged by the given amount
                if didUserDrag && !performPanChange(translation: translation)
                {
                    if _outerScrollView !== nil
                    {
                        // We can stop dragging right now, and let the scroll view take control
                        _outerScrollView = nil
                        _isDragging = false
                    }
                }
                else
                {
                    if _outerScrollView !== nil
                    {
                        // Prevent the parent scroll view from scrolling
                        _outerScrollView?.nsuiIsScrollEnabled = false
                    }
                }
                
                _lastPanPoint = recognizer.translation(in: self)

@liuxuan30
Copy link
Member

I just came across #2413, you can try 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

2 participants