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

unable to set dot on multiple graph #165

Open
khush004 opened this issue Feb 20, 2019 · 1 comment
Open

unable to set dot on multiple graph #165

khush004 opened this issue Feb 20, 2019 · 1 comment

Comments

@khush004
Copy link

khush004 commented Feb 20, 2019

Thank you for this awesome library but I am facing some issue with adding dot on graph

I want something like this
screen shot 2019-02-20 at 2 56 07 pm

and I have used following code for adding dots on graph
achieving this

@IBOutlet var viewGraph: UIView!

var arrPink = [1, 2, 3, 1, 2, 3, 4, 1, 5, 1]
var arrBlue = [2, 3, 1, 2, 3, 1, 3, 2, 3, 4]

override func viewDidLoad() {
    super.viewDidLoad()
    let graphView = ScrollableGraphView(frame: CGRect(x: 0, y: 0, width: viewGraph.frame.size.width, height: viewGraph.frame.size.height), dataSource: self)

    // Setup the second line plot.
    let orangeLinePlot = LinePlot(identifier: "orange")
    
    orangeLinePlot.lineWidth = 3
    orangeLinePlot.lineColor = #colorLiteral(red: 0.7492650747, green: 0.1955875754, blue: 0.3992423117, alpha: 1)
    orangeLinePlot.lineStyle = ScrollableGraphViewLineStyle.smooth
    
    orangeLinePlot.shouldFill = true
    orangeLinePlot.fillType = ScrollableGraphViewFillType.solid
    orangeLinePlot.fillColor = #colorLiteral(red: 0.7492650747, green: 0.1955875754, blue: 0.3992423117, alpha: 0.5)
    
    orangeLinePlot.adaptAnimationType = ScrollableGraphViewAnimationType.elastic

    // Setup the line plot.
    let blueLinePlot = LinePlot(identifier: "blue")
    
    blueLinePlot.lineWidth = 3
    blueLinePlot.lineColor = #colorLiteral(red: 0.07505937666, green: 0.6328803301, blue: 0.7182216644, alpha: 1)
    blueLinePlot.lineStyle = ScrollableGraphViewLineStyle.smooth
    
    blueLinePlot.shouldFill = true
    blueLinePlot.fillType = ScrollableGraphViewFillType.solid
    blueLinePlot.fillColor = #colorLiteral(red: 0.07450980392, green: 0.631372549, blue: 0.7176470588, alpha: 0.5)
    
    blueLinePlot.adaptAnimationType = ScrollableGraphViewAnimationType.elastic
    
    let blueDotPlot = DotPlot(identifier: "blueDot")
    blueDotPlot.dataPointType = ScrollableGraphViewDataPointType.circle
    blueDotPlot.dataPointSize = 4
    blueDotPlot.dataPointFillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
    
    blueDotPlot.adaptAnimationType = ScrollableGraphViewAnimationType.elastic
   
    graphView.backgroundFillColor = #colorLiteral(red: 0.1172487214, green: 0.1462360024, blue: 0.2590934336, alpha: 1)
    self.view.backgroundColor = #colorLiteral(red: 0.1172487214, green: 0.1462360024, blue: 0.2590934336, alpha: 1)
    
    graphView.dataPointSpacing = 80
    graphView.shouldAnimateOnStartup = true
    graphView.shouldAdaptRange = true
    
    graphView.shouldRangeAlwaysStartAtZero = true
    
    let dotPlot = DotPlot(identifier: "darkLineDot") // Add dots as well.
    dotPlot.dataPointSize = 4
    dotPlot.dataPointFillColor = UIColor.white
    dotPlot.adaptAnimationType = ScrollableGraphViewAnimationType.elastic

    let referenceLines = ReferenceLines()
    
    referenceLines.referenceLineLabelFont = UIFont.boldSystemFont(ofSize: 8)
    referenceLines.referenceLineColor = UIColor.clear
    referenceLines.referenceLineLabelColor = UIColor.clear
    referenceLines.relativePositions = [0, 0.2, 0.4, 0.6, 0.8, 1]
    
    referenceLines.dataPointLabelColor = UIColor.white.withAlphaComponent(1)
    // Add everything to the graph.
    graphView.addReferenceLines(referenceLines: referenceLines)
    graphView.addPlot(plot: blueLinePlot)

    graphView.addPlot(plot: blueDotPlot)
    graphView.addPlot(plot: orangeLinePlot)

    graphView.addPlot(plot: dotPlot)

    viewGraph.addSubview(graphView)
    
    // Do any additional setup after loading the view, typically from a nib.
    
}

but the issue is that dot is plotting on on one bar I am unable to add dot on both bar please check bellowed screen shot and please help me where I was wrong.

screen shot 2019-02-20 at 2 57 41 pm

@badiibs
Copy link

badiibs commented Nov 27, 2019

Check the DataSource functions !

func value(forPlot plot: Plot, atIndex pointIndex: Int) -> Double {
switch(plot.identifier) {
case "blue": return Double(arrBlue[pointIndex])
case "blueDot": return Double(arrBlue[pointIndex])
case "orange": return Double(arrPink[pointIndex])
case "darkLineDot": return Double(arrPink[pointIndex])
default:
return 0
}
}

   func label(atIndex pointIndex: Int) -> String {
        return "FEB \(pointIndex)"
   }
   
   func numberOfPoints() -> Int {
    var numberOfDataPointsInGraph = arrBlue.count
       return numberOfDataPointsInGraph
   }

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