Ios-Charts How to Put Uiimage Beside a Point

iOS-Charts How to put UIImage beside a point

You can modify private func drawCircles(context context: CGContext)
inside LineChartRenderer.swift to do the following: inside the loop where the circles are drawing use pt var which is calculated there and add something like this:

let image = UIImage(named: numbers[i])
image?.drawInRect(CGRect(x: pt.x, y: pt.y, width: 16, height: 16))

Obviously, you need to play with CGRect to place images the way you need. This method will be called every time device orientation will be changing etc.

How can I highlight the lowest data point in iOS-Charts?

In BarChartRenderer class you can find method

public override func drawValues(context context: CGContext)

inside body of if (!dataSet.isStacked) in the for-loop you can first define the minimum value using e.value and corresponding valuePoint variable, so after loop you will have coordinates where the minimum value will be drawn and adding some offset you can draw also your marker

let image = UIImage(named: "MARKER")
image?.drawInRect(CGRect(x: valuePoint.x, y: SOME_OFFSET + valuePoint.y + (val >= 0.0 ? posOffset : negOffset), width: 16, height: 16))

Or in

public func drawDataSet(context context: CGContext, dataSet:
IBarChartDataSet, index: Int)

You can find barRect of the smallest bar and play with that results.

iOS-Charts: Set UIImageViews in accordance with PieChart's Pie positions?

let FDEG2RAD = CGFloat(M_PI / 180.0)
var drawAngles = chart.drawAngles
var absoluteAngles = chart.absoluteAngles
var animator = chart.animator
var center = chart.centerCircleBox
var r: CGFloat = YOUR_DRAWING_RADIUS_HERE

for (var i = 0; i < absoluteAngles.count; i++)
{
var offset = drawAngles[i] / 2.0
var x = (r * cos(((rotationAngle + absoluteAngles[i] - offset) * animator.phaseY) * FDEG2RAD) + center.x)
var y = (r * sin(((rotationAngle + absoluteAngles[i] - offset) * animator.phaseY) * FDEG2RAD) + center.y)

// Put whatever you want now on the x/y
}

How to use getPosition to get the last data entry position? Charts Pod

Did more research and testing I finally get it working.

In where you are setting the LineChartDataSet()

//data line setup
let line = LineChartDataSet(entries: lineChartEntry, label: "")
line.mode = .linear
line.colors = [color]
line.fillColor = .clear
line.drawFilledEnabled = true
line.drawCirclesEnabled = true

//remove old imageView when the new data comes in
if let viewWithTag = self.view.viewWithTag(100) {
viewWithTag.removeFromSuperview()
}

var colors = [UIColor]()
for i in 0..<lineChartEntry.count {
//only the last circle will show the image
if(i == lineChartEntry.count - 1) {
colors.append(color)

let point = lineChartView.getPosition(entry: lineChartEntry[lineChartEntry.count - 1], axis: .left) //get the x and y CGPoint
let image = UIImage(named: "heart")
let imageView = UIImageView(image: image!)
imageView.tag = (100)

if !point.x.isNaN && !point.y.isNaN {
imageView.frame = CGRect(x: point.x - 15, y: point.y - 15, width:30, height: 30) //set the frame in center
imageView.contentMode = .center
lineChartView.addSubview(imageView)
}
} else {
colors.append(UIColor.clear)
}
}

.
.
.
//other line data configurations

IOS-Charts Adjust circle radius for individual line chart data point

I solved this in an application by actually having multiple data sets, the second data set being used only for adding points on the same line but with a given circle radius. I checked with the developers of Charts and there's no other way to achieve it.

I have:

- (void)displayChartWithSet:(LineChartDataSet *)set highlightedSet:(LineChartDataSet *)highlightedSet {
set.drawValuesEnabled = NO;
set.drawCirclesEnabled = YES;
set.circleColors = [NSArray arrayWithObject:[UIColor clearColor]];
set.colors = [NSArray arrayWithObject:[UIColor whiteColor]];
set.lineWidth = 2.0f;
set.mode = LineChartModeHorizontalBezier;
//Builds the data to be presented from two distinct data sets
// one containing only points with a radius
LineChartData *data = [[LineChartData alloc] initWithDataSets:[NSArray arrayWithObjects:set, highlightedSet, nil]];
}

This allows me to add individual points to the highlighted set and then redraw the view when needed, or have a nil set and have no highlighted points. There's a further setup function for the highlighted data set that does the configuration of points.

yValues position on a BarChart

Add this line:

chart.drawValueAboveBarEnabled = false


Related Topics



Leave a reply



Submit