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

Data Showing 0 and 1 only in y-axis if array contains only 0.0 double values. #338

Closed
manojchandola opened this issue Sep 2, 2015 · 3 comments

Comments

@manojchandola
Copy link

LineChartDataSet *dataSet = [[LineChartDataSet alloc] initWithYVals:yVals label:strDisplayText];

If yVals contains all 0.0 values, then it shows 0 and 1 in the y-axis. But same records in android shows 0, 1, 2, 3,... .
Kindly, let me know the process to resolve this issue.

@danielgindi
Copy link
Collaborator

You can tell us what versions of the framework are you trying on iOS and Android, and show sample code on both platforms - so we can test to see the difference and debug.

@manojchandola
Copy link
Author

Here y-axis array has values zero (0). So it shows three zeros(0) and three one(1) over the y-axis.
When i tried to pass x-axis (xVals) array with zero(0) count and dataset has 26 records, then in android it shows graph with y-axis coordinate as {0.0,0.2,0.4,0.6,0.8} , whereas in iOS it does not draw the graph.
this line of code : [_graphView setData:data]; sends this error message " setData is nil ".

iOS Code:

for (NSMutableArray *vals in yValsSet) {
LineChartDataSet *dataSet = [[LineChartDataSet alloc] initWithYVals:vals label:subMetric.displayText];
dataSet.axisDependency = AxisDependencyRight;

            dataSet.lineWidth = 2.f;
            dataSet.circleRadius = 0.0f;
            dataSet.fillAlpha = 65/255.f;

            if ([subMetric.displayText.uppercaseString isEqualToString:@"HOGGED"]){
                [dataSet setColor:colorsArray[0]];
                [dataSet setCircleColor:UIColor.blackColor];
            }
            else if ([subMetric.displayText.uppercaseString isEqualToString:@"IDLE"]){
                [dataSet setColor:colorsArray[1]];
                [dataSet setCircleColor:UIColor.blackColor];
            }
            else if ([subMetric.displayText.uppercaseString isEqualToString:@"STUCK"]) {
                [dataSet setColor:colorsArray[2]];
                [dataSet setCircleColor:UIColor.blackColor];
            }
            else {
                if (_metric.subMetrics.count == 2) {
                    if (dataSets.count == 0) {
                        [dataSet setColor:colorsArray[1]];
                        [dataSet setCircleColor:UIColor.blackColor];
                    }
                    else{
                        [dataSet setColor:colorsArray[0]];
                        [dataSet setCircleColor:UIColor.blackColor];
                    }
                }
                else
                {
                    if (dataSets.count == 0) {
                        [dataSet setColor:colorsArray[0]];
                        [dataSet setCircleColor:UIColor.blackColor];
                    }
                }

            }
            dataSet.fillColor = UIColor.redColor;
            dataSet.highlightColor = [UIColor colorWithRed:24/255.f green:117/255.f blue:117/255.f alpha:1.f];
            dataSet.drawCirclesEnabled = false;
            dataSet.drawCircleHoleEnabled = false;

            [dataSets addObject:dataSet];
        }

    }

    LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];
    [data setValueTextColor:UIColor.whiteColor];
    data.highlightEnabled = false;
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:9.0]];
    [_graphView setData:data];

Android Code:

for (int matricCount = 0; matricCount < subMetrices.size(); matricCount++) {

        ArrayList<Entry> values = new ArrayList<>();
        xVals = new ArrayList<>();
        for (int lineDataCount = 0; lineDataCount < subMetrices.get(matricCount).getAxisData().size(); lineDataCount++) {
            if (subMetrices.get(matricCount).getAxisData().get(lineDataCount).getValueMetrics() != null && !subMetrices.get(matricCount).getAxisData().get(lineDataCount).getValueMetrics().isEmpty()) {
                if (subMetrices.get(matricCount).getAxisData().get(lineDataCount).isAvailable()) {
                    if (!subMetrices.get(matricCount).getAxisData().get(lineDataCount).isRefresh()) {
                        float yValue = (new Double(subMetrices.get(matricCount).getAxisData().get(lineDataCount).getValueMetrics())).floatValue();
                        xVals.add(Utils.getTimeFromMillisecond(subMetrices.get(matricCount).getAxisData().get(lineDataCount).getCreatedAt(), "HH:mm"));
                        values.add(new Entry(yValue, lineDataCount));
                    }/*else{
                    addPointToDataSet(matricCount,values);
                    values=new ArrayList<>();
                }*/
                } else {
                    addPointToDataSet(matricCount, values);
                    values = new ArrayList<>();
                }
            }
        }
        addPointToDataSet(matricCount, values);
    }


    LineData data = new LineData(xVals, dataSets);
    mChart.setData(data);
    mChart.animateX(1000, Easing.EasingOption.EaseInOutQuart);
    mChart.invalidate();

@danielgindi
Copy link
Collaborator

Well going back to this issue (sorry, too many issues I forgot about this) I understand that what you are missing is telling the chart what to do for axis min/max (customAxisMin/customAxisMax). Otherwise, the axis range is 0.0 to 0.0. And it enlarges it to 1.0.

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