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

noDataText doesn't work on CombinedChart (works fine on PieChart and BarChart) #1896

Closed
kkontus opened this issue Nov 30, 2016 · 5 comments
Closed

Comments

@kkontus
Copy link

kkontus commented Nov 30, 2016

Is there any difference how to set noDataText on CombinedChart? It works without any problem on PieChart and BarChart

@liuxuan30
Copy link
Member

As far as I can see:

if _data === nil && noDataText.characters.count > 0
{
}

This is the only condition the noDataText will be rendered for any chart.. So set the combinedData to nil.

@kkontus
Copy link
Author

kkontus commented Dec 5, 2016

Hi again. I tried that but .combinedData is get-only property so I set .data to nil, and checked your condition, it is always true and still doesn't work. Below is the code for creating combined graph, maybe you can get an idea what might be a problem.

Tnx

 func createCombinedGraph() -> CombinedChartView {

    var chartData: CombinedChartData? = nil
    
    if xValues.count > 0 && yValuesLineChart.count > 0 && yValuesBarChart.count > 0 {
        var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
        var yVals2 : [BarChartDataEntry] = [BarChartDataEntry]()
        
        for i in 0..<xValues.count {
            if lineGraphFilter == ConstantValuesHelper.filterBudget {
                yVals1.append(ChartDataEntry(x: Double(i+1), y: yValuesLineChart[i] / 100000, data: xValues as AnyObject?))
            } else if lineGraphFilter == ConstantValuesHelper.filterImpressions {
                yVals1.append(ChartDataEntry(x: Double(i+1), y: yValuesLineChart[i] / 1000000, data: xValues as AnyObject?))
            } else {
                yVals1.append(ChartDataEntry(x: Double(i+1), y: yValuesLineChart[i], data: xValues as AnyObject?))
            }
            
            if barGraphFilter == ConstantValuesHelper.filterBudget {
                yVals2.append(BarChartDataEntry(x: Double(i+1), y: yValuesBarChart[i] / 100000, data: xValues as AnyObject?))
            } else if barGraphFilter == ConstantValuesHelper.filterImpressions {
                yVals2.append(BarChartDataEntry(x: Double(i+1), y: yValuesBarChart[i] / 1000000, data: xValues as AnyObject?))
            } else {
                yVals2.append(BarChartDataEntry(x: Double(i+1), y: yValuesBarChart[i], data: xValues as AnyObject?))
            }
            
            //yVals1.append(ChartDataEntry(x: Double(i+1), y: yValuesLineChart[i], data: xValues as AnyObject?))
            //yVals2.append(BarChartDataEntry(x: Double(i+1), y: yValuesBarChart[i], data: xValues as AnyObject?))
        }
        
        let lineChartSet = LineChartDataSet(values: yVals1, label: lineGraphLabel)
        let barChartSet: BarChartDataSet = BarChartDataSet(values: yVals2, label: barGraphLabel)
        lineChartSet.drawValuesEnabled = false //show or hide labels on top of the bars
        barChartSet.drawValuesEnabled = false //show or hide labels on top of the bars
        //barChartSet.barShadowColor = UIColor.white.withAlphaComponent(0.0) //way to hide shadow (but we have combinedChartView.drawBarShadowEnabled = false)
        let barChartColor = UIColor.colorWithCustomValue(60.0, green: 220.0, blue: 78.0, alpha: 1.0)
        let lineChartColor = UIColor.colorWithCustomValue(240.0, green: 238.0, blue: 70.0, alpha: 1.0)
        barChartSet.setColor(barChartColor)
        lineChartSet.setColor(lineChartColor)
        lineChartSet.circleColors = [lineChartColor]
        
        chartData = Charts.CombinedChartData()
        chartData!.lineData = Charts.LineChartData(dataSets: [lineChartSet])
        chartData!.barData = Charts.BarChartData(dataSets: [barChartSet])
    }

    
    // formatting left axis labels
    let valueFormatter = NumberFormatter()
    valueFormatter.numberStyle = NumberFormatter.Style.decimal
    valueFormatter.locale = Locale(identifier: Localize.currentLanguage())
    valueFormatter.maximumFractionDigits = 2
    valueFormatter.minimumFractionDigits = 2
    valueFormatter.minimumIntegerDigits = 1
    ////valueFormatter.alwaysShowsDecimalSeparator = true
    //valueFormatter.usesGroupingSeparator = true
    combinedChartView.leftAxis.valueFormatter = DefaultAxisValueFormatter(formatter: valueFormatter)
    
    combinedChartView.xAxis.labelPosition = XAxis.LabelPosition.bottom
    combinedChartView.xAxis.drawAxisLineEnabled = false //show or hide X axis
    combinedChartView.xAxis.drawGridLinesEnabled = false //show or hide graph gridlines
    combinedChartView.rightAxis.drawLabelsEnabled = false //show or hide labels on Y axis on right side
    combinedChartView.leftAxis.drawAxisLineEnabled = false //show or hide left axis
    combinedChartView.rightAxis.drawAxisLineEnabled = false //show or hide right axis
    combinedChartView.chartDescription?.text = ""
    combinedChartView.noDataText = "Custom no chart data available."
    combinedChartView.drawBarShadowEnabled = false
    //combinedChartView.isUserInteractionEnabled = false // this would disable filter button also so it is not an option
    combinedChartView.scaleXEnabled = false
    combinedChartView.scaleYEnabled = false
    combinedChartView.pinchZoomEnabled = false
    combinedChartView.doubleTapToZoomEnabled = false
    combinedChartView.dragEnabled = false // this is important for swiping to another PageMenu tab, if this is true it won't work (but for now we don't have combined graph on PageMenu)
    combinedChartView.minOffset = 15.0
    combinedChartView.extraTopOffset = 30.0
    combinedChartView.legend.yOffset = 9.0
    
    //combinedChartView.data = chartData
    //combinedChartView.combinedData = chartData // combinedData is get-only property so we can't set it here, we use combinedChartView.data
    
    // added for testing
    combinedChartView.data = nil
    //combinedChartView.notifyDataSetChanged() // also no change using this
    
    //here is the code that you said is the only condition
    if combinedChartView.combinedData === nil && combinedChartView.noDataText.characters.count > 0 {
        print("In this case it should show Custom no chart data available.") // we get here every time and noDataText is ever changed
    } else {
        print("Get here if we have data")
    }
    
    
    return combinedChartView
}

@liuxuan30
Copy link
Member

liuxuan30 commented Dec 6, 2016

I tried with ChartsDemo:

- (void)setChartData
{
    CombinedChartData *data = [[CombinedChartData alloc] init];
    data.lineData = [self generateLineData];
    data.barData = [self generateBarData];
    data.bubbleData = [self generateBubbleData];
    data.scatterData = [self generateScatterData];
    data.candleData = [self generateCandleData];
    
    _chartView.xAxis.axisMaximum = data.xMax + 0.25;

    _chartView.data = nil;
}

It works as expected, showing 'No chart data available' in combined chart.
You may want to check your code.. Or add break point at the condition so you know where you get the data.

@kkontus
Copy link
Author

kkontus commented Dec 6, 2016

@liuxuan30 it works with default text (No chart data available.), but I can't set custom string as I can do it with BarChart and PieChart. Regarding what is combinedData, you said that I need to set it to nil, but since combinedData is get-only property I can only set .data property to nil, and in the code above I'm just checking if conditions are met (which they are, both combinedData and data are nil and noDataText is set). I also added breakpoint to your code that check if conditions are met (inside ChartViewBase). Can you please check if your example works when you set custom string to noDataText.
Thank you

@kkontus
Copy link
Author

kkontus commented Dec 6, 2016

Ok, solved, it was my mistake, setting noDataText in viewDidAppear was the problem + combinedChartView.notifyDataSetChanged() needs to be called, while on BarChart and PieChart that's not needed (at least in my case).

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

2 participants