Last active
September 21, 2018 05:34
-
-
Save ArsenyMalkov/22c419d56980e6ce7b7237446f874b7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LineChartActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_chart_common); | |
AnyChartView anyChartView = findViewById(R.id.any_chart_view); | |
anyChartView.setProgressBar(findViewById(R.id.progress_bar)); | |
new LongOperation(anyChartView).execute(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LongOperation extends AsyncTask<Void, Void, Wrapper> { | |
private AnyChartView anyChartView; | |
public LongOperation(AnyChartView anyChartView) { | |
this.anyChartView = anyChartView; | |
} | |
@Override | |
protected Wrapper doInBackground(Void... params) { | |
List<DataEntry> seriesData = new ArrayList<>(); | |
List<List<Score>> allScores = new ArrayList<>(); | |
allScores.add(Score.getDummyScores()); | |
allScores.add(Score.getDummyScores()); | |
allScores.add(Score.getDummyScores()); | |
List<DataEntry> seriesData = new ArrayList<>(); | |
seriesData.add(new CustomDataEntry("Seq 1", Stream.of(allScores.get(0)).map(Score::getFirstSequenceMark).collect(Collectors.toList()))); | |
seriesData.add(new CustomDataEntry("Seq 2", Stream.of(allScores.get(0)).map(Score::getSecondSequenceMark).collect(Collectors.toList()))); | |
seriesData.add(new CustomDataEntry("Seq 3", Stream.of(allScores.get(1)).map(Score::getFirstSequenceMark).collect(Collectors.toList()))); | |
seriesData.add(new CustomDataEntry("Seq 4", Stream.of(allScores.get(1)).map(Score::getSecondSequenceMark).collect(Collectors.toList()))); | |
seriesData.add(new CustomDataEntry("Seq 5", Stream.of(allScores.get(2)).map(Score::getFirstSequenceMark).collect(Collectors.toList()))); | |
seriesData.add(new CustomDataEntry("Seq 6", Stream.of(allScores.get(2)).map(Score::getSecondSequenceMark).collect(Collectors.toList()))); | |
return new Wrapper(seriesData, allScores); | |
} | |
@Override | |
protected void onPostExecute(Wrapper wrapper) { | |
List<DataEntry> seriesData = wrapper.getSeriesData(); | |
List<List<Score>> allScores = wrapper.getAllScores(); | |
Cartesian cartesian = AnyChart.line(); | |
cartesian.animation(true); | |
cartesian.padding(0d, 0d, 20d, 8d); | |
cartesian.crosshair().enabled(true); | |
cartesian.crosshair() | |
.yLabel(true) | |
.yStroke((Stroke) null, null, null, (String) null, (String) null); | |
cartesian.tooltip().positionMode(TooltipPositionMode.POINT); | |
cartesian.yAxis(0).title("Mark/20"); | |
cartesian.xAxis(0).labels().padding(5d, 5d, 5d, 5d); | |
Set set = Set.instantiate(); | |
set.data(seriesData); | |
Mapping mapping0 = set.mapAs("{ x: 'x', value: 'value' }"); | |
Line series0 = cartesian.line(mapping0); | |
series0.name(allScores.get(0).get(0).getCourse().getAbbr()); | |
series0.hovered().markers().enabled(true); | |
series0.hovered().markers() | |
.type(MarkerType.CIRCLE) | |
.size(4d); | |
series0.tooltip() | |
.position("right") | |
.anchor(Anchor.LEFT_CENTER) | |
.offsetX(5d) | |
.offsetY(5d); | |
for (int i = 1; i < allScores.get(0).size(); i++) { | |
Mapping mapping = set.mapAs("{ x: 'x', value: 'value" + i + "' }"); | |
Line series = cartesian.line(mapping); | |
series.name(allScores.get(0).get(i).getCourse().getAbbr()); | |
series.hovered().markers().enabled(true); | |
series.hovered().markers() | |
.type(MarkerType.CIRCLE) | |
.size(4d); | |
series.tooltip() | |
.position("right") | |
.anchor(Anchor.LEFT_CENTER) | |
.offsetX(5d) | |
.offsetY(5d); | |
} | |
cartesian.legend().enabled(true); | |
cartesian.legend().fontSize(13d); | |
cartesian.legend().padding(0d, 16d, 10d, 16d); | |
anyChartView.setChart(cartesian); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Wrapper { | |
public List<DataEntry> seriesData; | |
public List<List<Score>> allScores; | |
public Wrapper(List<DataEntry> seriesData, List<List<Score>> allScores) { | |
this.seriesData = seriesData; | |
this.allScores = allScores; | |
} | |
public List<DataEntry> getSeriesData() { | |
return seriesData; | |
} | |
public List<List<Score>> getAllScores() { | |
return allScores; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment