This is a migrated thread and some comments may be shown as answers.

Track Ball for trend chart

1 Answer 67 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Megharaj
Top achievements
Rank 1
Megharaj asked on 18 Mar 2016, 04:44 AM

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.

(CODE:)

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.addSeries(seriesForExpenses)
                    chart.backgroundColor = UIColor.whiteColor()
                }
            chart.legend.hidden = false
            //trackball

            let color = UIColor.redColor()
            let size = CGSizeMake(20, 20)
            let shape = TKPredefinedShape(type: TKShapeType.Rhombus, andSize: size)
            chart.trackball.line.style.verticalLineStroke = TKStroke(color: color, width: 2.0)
            chart.trackball.line.style.pointShapeFill = TKSolidFill(color: color)
            chart.trackball.line.style.pointShape = 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
            chart.update()
            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
        }
    }

 

 

1 Answer, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 22 Mar 2016, 01:16 PM
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.

Regards,
Adrian
Telerik
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
Tags
Chart
Asked by
Megharaj
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Share this question
or