Created
November 22, 2019 04:45
-
-
Save Shestac92/7088a64dcc92ef7e7488ac1d12d19055 to your computer and use it in GitHub Desktop.
Bar chart with conditional coloring
This file contains 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
AnyChartView anyChartView = findViewById(R.id.any_chart_view); | |
Cartesian cartesian = AnyChart.bar(); //Anychart Bar returns the Cartesian Object | |
cartesian.animation(true); | |
cartesian.title("Persönliche Auswertung - Motivationprofil"); | |
cartesian.padding(10d, 20d, 5d, 20d); | |
cartesian.yScale().stackMode(ScaleStackMode.VALUE); | |
cartesian.yAxis(0).labels().format( | |
"function() {return Math.abs(this.value);}"); | |
cartesian.xAxis(1) | |
.enabled(true) | |
.orientation(Orientation.RIGHT) | |
.overlapMode(LabelsOverlapMode.ALLOW_OVERLAP); | |
Set set = Set.instantiate(); | |
List<DataEntry> data = new ArrayList<>(); | |
data.add(new ValueDataEntry("a", 2)); | |
data.add(new ValueDataEntry("b", 5.43)); | |
data.add(new ValueDataEntry("c", -1.07)); | |
data.add(new ValueDataEntry("d", 4.5)); | |
data.add(new ValueDataEntry("e", -2.7)); | |
data.add(new ValueDataEntry("f", 0)); | |
set.data(data); | |
Mapping series1Data = set.mapAs("{ x: 'x', value: 'value'}"); | |
Bar barseries= cartesian.bar(series1Data); | |
barseries.fill("function() {" + | |
"if (this.value < -2 || this.value > 2)\n" + | |
"return 'blue'\n" + | |
"return 'red'\n" + | |
"}"); | |
anyChartView.setChart(cartesian); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment