lecho / hellocharts-android

Charts library for Android compatible with API 8+, several chart types with scaling, scrolling and animations 📊
Apache License 2.0
7.43k stars 1.61k forks source link

Multiple data sets in a single LineChartView #456

Closed roeiros closed 6 years ago

roeiros commented 6 years ago

Hello, I started using HelloCharts library and found some difficulties with adding two sets of data into my LineChartView. This is how I'm doing it:

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_user_details, container, false);
        performanceChart = (LineChartView)rootView.findViewById(R.id.performanceChart);
        performanceChart.setInteractive(false);
        addScoreEntriesToChart();
        addRankEntriesToChart();

        return rootView;
    }

private void addScoreEntriesToChart() {
        List<PointValue> values = new ArrayList<PointValue>();
        ArrayList<Double> latestScores = currentPlayer.getLatestScores();
        for(int i = 0; i < latestScores.size(); i++){
            values.add(new PointValue(i+1, Float.valueOf(String.valueOf(latestScores.get(i)))));
        }
        performanceChart.setLineChartData(getLineSettings(values, Color.parseColor("#0036D9")));

    }

    private void addRankEntriesToChart() {
        List<PointValue> values = new ArrayList<PointValue>();
        ArrayList<Integer> latestRanks = currentPlayer.getLatestRanks();
        for(int i = 0; i < latestRanks.size(); i++){
            values.add(new PointValue(i+1, Float.valueOf(latestRanks.get(i))));
        }
        performanceChart.setLineChartData(getLineSettings(values, Color.parseColor("#84BE67")));
    }

    @NonNull
    private LineChartData getLineSettings(List<PointValue> values, int lineColor) {
        Line line = new Line(values).setColor(lineColor).setCubic(true);
        line.setStrokeWidth(2);
        line.setPointRadius(0);
        List<Line> lines = new ArrayList<Line>();
        lines.add(line);

        LineChartData data = new LineChartData();
        data.setLines(lines);
        return data;
    }

I'm probably doing something wrong because i end up seeing only one line on the LineChartView (RankEntries - the last one added). Trying to Google the issues didn't get me the answer. Any help would be appreciated :)

fllaryora commented 4 years ago

I am having the same problem. And I am trying to fix it.

fllaryora commented 4 years ago

Seams to be a scalling problemin my case..