As the title described, i want to draw only one circle one a specific value, but right now it draw all the values.
I want

I got

code
func configureLines() {
var set:LineChartDataSet?
if let count = data?.dataSetCount, count > 0 {
set = data?.dataSets[0] as? LineChartDataSet;
set?.values = chartDataValues
data?.notifyDataChanged()
notifyDataSetChanged()
} else {
set = LineChartDataSet(values: chartDataValues, label: "DataSet 1")
set?.axisDependency = .left
set?.drawValuesEnabled = false
set?.valueTextColor = UIColor.green
set?.circleRadius = 4
set?.drawCirclesEnabled = true
set?.drawCircleHoleEnabled = false
// set?.highlightColor = UIColor.red
set?.highlightEnabled = false
set?.setCircleColor(UIColor.yellowFontColor)
set?.fillColor = UIColor.chartFillColor
set?.fillAlpha = 1.0
set?.drawFilledEnabled = true
set?.setColor(UIColor.yellowFontColor)
set?.lineWidth = 1
print(set!)
var dataSets = [LineChartDataSet]()
dataSets.append(set!)
let data = LineChartData(dataSets: dataSets)
data.setValueTextColor(UIColor.red)
self.data = data
}
}
How should i make it just show one circle ?
combine scatter chart with one point and line chart
set set?.drawCirclesEnabled = true to false, and override drawHighlighted() or drawCircles() to just draw highlight circle for specific value.
HI @liuxuan30
Follow your idea, i am trying to subclass LineChartRenderer then reassign the render variable to the subclass render. Then use it on my subclass LineChartView. I am not sure if i understood correct. I can't override drawCircles() drawExtras can be override, and it call drawCircles inside.
But my problem is i can't find the parameter used by the render init. I think i am wrong. Here's my code. Thank you for any help!
class BSLineChartRenderer: LineChartRenderer {
override func drawExtras(context: CGContext) {
}
}
class BSMyWealthLineChartView: LineChartView {
var chartDataValues = [ChartDataEntry]()
override init(frame: CGRect) {
super.init(frame: frame)
// init(dataProvider: LineChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?)
renderer = DBSLineChartRenderer() //Without dataProvider etc.
}
just like how line chart view does:
internal override func initialize()
{
super.initialize()
renderer = LineChartRenderer(dataProvider: self, animator: _animator, viewPortHandler: _viewPortHandler)
}
HI @liuxuan30 There are errors like
"Static member 'initialize' cannot be used on instance of type 'LineChartView'
As attached:

are you defining outside of the framework, so restricted by interval?
@liuxuan30 You tell to override drawHighlighted(), but how should one subclass LineChartRenderer and override drawHighlighted() when several necessary properties and functions are internal?
@liuxuan30 Seems as though these properties that we would need in order to write our own custom renderer are internal, so we wouldn't be able too. Is it possible to create a protocol function that allows us to decide whether a circle is drawn at a specific point. So that you can keep these properties internal.
Just in case anyone else is looking to do the same... the easiest solution is to draw a second data set that consists of only a single value. Turn off the circles on the first set that produces the line and then turn on the circle for the second set. You can use
LineChartView.lineData?.addDataSet(set)
@MobileVet You're the best man! Thank you very much!!!! 馃殌
import Foundation
import CoreGraphics
import Charts
/// Chart that draws lines, surfaces, circles, ...
open class StrategyLineChartView: LineChartView {
public override init(frame: CGRect)
{
super.init(frame: frame)
renderer = StrategyLineChartRenderer(dataProvider: self, animator: chartAnimator, viewPortHandler: viewPortHandler)
}
public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
renderer = StrategyLineChartRenderer(dataProvider: self, animator: chartAnimator, viewPortHandler: viewPortHandler)
}
}
Most helpful comment
Just in case anyone else is looking to do the same... the easiest solution is to draw a second data set that consists of only a single value. Turn off the circles on the first set that produces the line and then turn on the circle for the second set. You can use
LineChartView.lineData?.addDataSet(set)