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

Single point on line chart not showing - Swift 3 #2455

Closed
thundercatchris opened this issue May 18, 2017 · 1 comment
Closed

Single point on line chart not showing - Swift 3 #2455

thundercatchris opened this issue May 18, 2017 · 1 comment

Comments

@thundercatchris
Copy link

thundercatchris commented May 18, 2017

When I have multiple points in an array for a line on a line graph, everything shows perfectly. But when there is only one point, the dot does not show. I dont know why? the delegate is being set elsewhere, but this doesnt seem to be the issue.

The below examples shows Test 2 and Test exercise. The first image is where each has one value, the second they each have 2.

heres my code

func startChart(){

     chart.dragEnabled = true
     chart.legend.form = .circle
     chart.drawGridBackgroundEnabled = false

     let xaxis = chart.xAxis

     xaxis.valueFormatter = axisFormatDelegate
     xaxis.labelCount = dataSets.count
     xaxis.labelPosition = .bottom

     xaxis.granularityEnabled = true
     xaxis.granularity = 1.0
     xaxis.avoidFirstLastClippingEnabled = true
     xaxis.forceLabelsEnabled = true
     let rightAxis = chart.rightAxis

     rightAxis.enabled = false
     rightAxis.axisMinimum = 0

     let leftAxis = chart.leftAxis
     leftAxis.drawGridLinesEnabled = true
     leftAxis.axisMinimum = 0

     let chartData = LineChartData(dataSets: dataSets)
     chart.data = chartData
}

If I add

chart.setVisibleXRangeMinimum(myMinDate)

the value will show correctly. however it squashes the value to the left and overlaps 2 x value dates

untitled
untitled2

`

@thundercatchris
Copy link
Author

The only way I could get around this was to add an additional invisible line.

I created a clear line that started the day before and ended the day after my single values.

As long as there is a line on the chart that goes from one point to another, the other single values show.

  var singleValue = false
    for i in 0...(dataSets.count - 1) {
        if dataSets[i].values.count > 1{
            singleValue = true
        }
    }
    var data = dataSets
    if singleValue == false {
        let minNS = Calendar.current.date(byAdding: .day, value: -1, to: minNSDate as! Date)
        let maxNS =  Calendar.current.date(byAdding: .day, value: 1, to: maxNSDate as! Date)

        var dataEntries: [ChartDataEntry] = []

        let dataEntry1 = ChartDataEntry(x:Double(String(format: "%.2f",Double((minNS?.timeIntervalSince1970)!)))!,y:00.00)
        let dataEntry2 = ChartDataEntry(x:Double(String(format: "%.2f",Double((maxNS?.timeIntervalSince1970)!)))!,y:00.00)
        dataEntries.append(dataEntry1)
        dataEntries.append(dataEntry2)
        let set = LineChartDataSet(values: dataEntries, label: "")
        set.setCircleColor(UIColor.clear)
        set.circleHoleColor = UIColor.clear
        set.setColor(UIColor.white, alpha: 0.0)
        set.drawValuesEnabled = false
        data.append(set)

    }
    chart.chartDescription?.text = ""
    let chartData = LineChartData(dataSets: data)
    chart.data = chartData

untitled

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

1 participant