Track Ball for trend chart

2 posts, 0 answers
  1. Megharaj
    Megharaj avatar
    28 posts
    Member since:
    May 2015

    Posted 17 Mar Link to this post

    Dear Telerik Team,

    In my App, I am preparing the charts & showing it in a tableview cell (can look at the images in the attachment). 

    for Trend charts i would like to show a track ball, here i am sharing the code of mine(I have tried the code from some document of telerik but no luck).

    any help on this will be appreciated.


    if title == "trend"{
                var arr1: Array<Array<String>> = seriess
                let chart = TKChart(frame: CGRectInset(CGRectMake(0,3, screenBounds.size.width, 300), 5, 0))
                for var j = 0; j < arr1.count; j++ {
                    var arr : Array<String> = arr1[j]
                    var ActulaData = [TKChartDataPoint]()
                        for var i = 0; i < arr.count; i++ {
                            var actual = ""
                            actual = arr[i]
                            actual = actual.stringByReplacingOccurrencesOfString(",", withString: "")
                            var act: Int? = (actual as NSString).integerValue //actual.toInt()
                            ActulaData.append(TKChartDataPoint(x: categry[i], y: act))
                        let seriesForExpenses = TKChartLineSeries(items: ActulaData)
                        seriesForExpenses.title = series_titles[j]
                        chart.backgroundColor = UIColor.whiteColor()
                chart.legend.hidden = false

                let color = UIColor.redColor()
                let size = CGSizeMake(20, 20)
                let shape = TKPredefinedShape(type: TKShapeType.Rhombus, andSize: size)
       = TKStroke(color: color, width: 2.0)
       = TKSolidFill(color: color)
       = shape
                chart.delegate = self

                let gridStyle = chart.gridStyle
                gridStyle.horizontalLineStroke = TKStroke(color: UIColor.lightGrayColor())
                gridStyle.horizontalLineAlternateStroke = TKStroke(color:UIColor.lightGrayColor())
                gridStyle.horizontalFill = TKSolidFill(color: UIColor.whiteColor())
                gridStyle.horizontalAlternateFill = TKSolidFill(color: UIColor.whiteColor())
                gridStyle.horizontalLinesHidden = false
                gridStyle.verticalLinesHidden = true
                Cell4! .addSubview(chart)
                chart.xAxis?.style.labelStyle.font = UIFont.systemFontOfSize(8)
                chart.yAxis?.style.labelStyle.font = UIFont.systemFontOfSize(8)
                chart.yAxis?.style.lineHidden = false
                chart.yAxis?.style.lineStroke.width = 2
                chart.yAxis?.title = axis
                chart.yAxis?.style.titleStyle.rotationAngle = CGFloat(-M_PI_2)
                chart.title.hidden = false
                chart.title.text = chartTitle
                chart.title.textColor = UIColor .blackColor()
                chart.title.textAlignment = NSTextAlignment.Center
                Cell4!.backgroundColor =  UIColor(red: 248/255, green: 248/255, blue: 255/255, alpha: 1.0)
                return Cell4!


        func chart(chart: TKChart, trackballDidTrackSelection selection: [AnyObject]) {
            if selection.count > 0 {
                let value: AnyObject = (selection[0] as! TKChartSelectionInfo).dataPoint!.dataXValue
                let str = "Pos=\(value)"
                chart.trackball.tooltip.text = str



  2. Adrian
    Adrian avatar
    160 posts

    Posted 22 Mar Link to this post

    Hello, Megharaj,

    Thank you for writing.

    To use trackball in TKChart you should set its allowTrackball property to true. Consider the code below:
    chart.allowTrackball = true

    You can read more about the trackball feature in TKChart in our documentation.
    I hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
Back to Top