Created
July 11, 2018 09:01
-
-
Save ArsenyMalkov/5677365c4c5f4879bd1bf7daccee19b5 to your computer and use it in GitHub Desktop.
Gauges
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<com.anychart.anychart.AnyChartView | |
android:id="@+id/any_chart_view" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
/> | |
<ProgressBar | |
android:id="@+id/progress_bar" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
/> | |
</android.support.constraint.ConstraintLayout> |
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 LinearColorScaleActivity 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)); | |
ChartsLinearGauge linearGauge = AnyChart.linear(); | |
linearGauge.setData(new SingleValueDataSet(new Double[] { 5.3D })); | |
linearGauge.setLayout(Layout.HORIZONTAL); | |
linearGauge.getLabel(0) | |
.setPosition(Position.LEFT_CENTER) | |
.setAnchor(EnumsAnchor.LEFT_CENTER) | |
.setOffsetY("-50px") | |
.setOffsetX("50px") | |
.setFontColor("black") | |
.setFontSize(17); | |
linearGauge.getLabel(0).setText("Total Rainfall"); | |
linearGauge.getLabel(1) | |
.setPosition(Position.LEFT_CENTER) | |
.setAnchor(EnumsAnchor.LEFT_CENTER) | |
.setOffsetY("40px") | |
.setOffsetX("50px") | |
.setFontColor("#777777") | |
.setFontSize(17); | |
linearGauge.getLabel(1).setText("Drought Hazard"); | |
linearGauge.getLabel(2) | |
.setPosition(Position.RIGHT_CENTER) | |
.setAnchor(EnumsAnchor.RIGHT_CENTER) | |
.setOffsetY("40px") | |
.setOffsetX("50px") | |
.setFontColor("#777777") | |
.setFontSize(17); | |
linearGauge.getLabel(2).setText("Flood Hazard"); | |
OrdinalColor scaleBarColorScale = new OrdinalColor(); | |
scaleBarColorScale.setRanges( | |
"[\n" + | |
" {\n" + | |
" from: 0,\n" + | |
" to: 2,\n" + | |
" color: ['red 0.5']\n" + | |
" },\n" + | |
" {\n" + | |
" from: 2,\n" + | |
" to: 3,\n" + | |
" color: ['yellow 0.5']\n" + | |
" },\n" + | |
" {\n" + | |
" from: 3,\n" + | |
" to: 7,\n" + | |
" color: ['green 0.5']\n" + | |
" },\n" + | |
" {\n" + | |
" from: 7,\n" + | |
" to: 8,\n" + | |
" color: ['yellow 0.5']\n" + | |
" },\n" + | |
" {\n" + | |
" from: 8,\n" + | |
" to: 10,\n" + | |
" color: ['red 0.5']\n" + | |
" }\n" + | |
" ]"); | |
linearGauge.getScaleBar(0) | |
.setWidth("5%") | |
.setColorScale(scaleBarColorScale); | |
linearGauge.marker(0) | |
.setType(MarkerType.TRIANGLE_DOWN) | |
.setColor("red") | |
.setOffset("-3.5%") | |
.setZIndex(10); | |
linearGauge.getScale() | |
.setMinimum(0) | |
.setMaximum(10); | |
linearGauge.getAxis() | |
.setMinorTicks(false) | |
.setWidth("1%"); | |
linearGauge.getAxis() | |
.setOffset("-1.5%") | |
.setOrientation(Orientation.TOP) | |
.setLabels("top"); | |
linearGauge.setPadding(0, 30, 0, 30); | |
anyChartView.setChart(linearGauge); | |
} | |
} |
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 ThermometerActivity 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)); | |
ChartsLinearGauge linearGauge = AnyChart.linear(); | |
linearGauge.setData(new SingleValueDataSet(new Integer[] { 2 })); | |
linearGauge.getTooltip() | |
.setUseHtml(true) | |
.setFormat( | |
"function () {\n" + | |
" return this.value + '°' + 'C' +\n" + | |
" ' (' + (this.value * 1.8 + 32).toFixed(1) +\n" + | |
" '°' + 'F' + ')'\n" + | |
" }"); | |
linearGauge.getLabel(0).setUseHtml(true); | |
linearGauge.getLabel(0) | |
.setText("C°") | |
.setPosition(Position.LEFT_BOTTOM) | |
.setAnchor(EnumsAnchor.LEFT_BOTTOM) | |
.setOffsetY("20px") | |
.setOffsetX("38%") | |
.setFontColor("black") | |
.setFontSize(17); | |
linearGauge.getLabel(1).setUseHtml(true); | |
linearGauge.getLabel(1) | |
.setText("F°") | |
.setPosition(Position.RIGHT_BOTTOM) | |
.setAnchor(EnumsAnchor.RIGHT_BOTTOM) | |
.setOffsetY("20px") | |
.setOffsetX("47.5%") | |
.setFontColor("black") | |
.setFontSize(17); | |
ScalesBase scale = linearGauge.getScale() | |
.setMinimum(-30) | |
.setMaximum(40); | |
linearGauge.getAxis().setScale(scale); | |
linearGauge.getAxis() | |
.setOffset("-1%") | |
.setWidth("0.5%"); | |
linearGauge.getAxis().getLabels() | |
.setFormat("{%Value}°") | |
.setUseHtml(true); | |
linearGauge.thermometer(0) | |
.setName("Thermometer") | |
.setId(1); | |
linearGauge.getAxis(0).setMinorTicks(true); | |
linearGauge.getAxis(0).getLabels() | |
.setFormat( | |
"function () {\n" + | |
" return '<span style=\"color:black;\">' + this.value + '°</span>'\n" + | |
" }") | |
.setUseHtml(true); | |
linearGauge.getAxis(1).setMinorTicks(true); | |
linearGauge.getAxis(1).getLabels() | |
.setFormat( | |
"function () {\n" + | |
" return '<span style=\"color:black;\">' + this.value + '°</span>'\n" + | |
" }") | |
.setUseHtml(true); | |
linearGauge.getAxis(1) | |
.setOffset("3.5%") | |
.setOrientation(Orientation.RIGHT); | |
ScalesLinear linear = new ScalesLinear(); | |
linear.setMinimum(-20) | |
.setMaximum(100); | |
linearGauge.getAxis(1).setScale(linear); | |
anyChartView.setChart(linearGauge); | |
} | |
} |
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 WindDirectionActivity 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)); | |
CircularGauge circularGauge = AnyChart.circular(); | |
circularGauge.setFill("#fff") | |
.setStroke("null") | |
.setPadding(0, 0, 0, 0) | |
.setMargin(30, 30, 30, 30); | |
circularGauge.setStartAngle(0) | |
.setSweepAngle(360); | |
circularGauge.setData(new SingleValueDataSet(new Double[] { 18.1 })); | |
circularGauge.getAxis() | |
.setStartAngle(0) | |
.setRadius(80) | |
.setSweepAngle(360) | |
.setWidth(3) | |
.setDrawFirstLabel(false) | |
.setTicks("{ type: 'line', length: 4, position: 'outside' }"); | |
circularGauge.getAxis().getLabels() | |
.setPosition("outside") | |
.setUseHtml(true); | |
circularGauge.getAxis().getLabels().setFormat( | |
"function () {\n" + | |
" return this.value + '°'\n" + | |
" }"); | |
circularGauge.getAxis().getScale() | |
.setMinimum(0) | |
.setMaximum(360); | |
circularGauge.getAxis().getScale() | |
.setTicks("{interval: 45}") | |
.setMinorTicks("{interval: 10}"); | |
circularGauge.getMarker() | |
.setFill("#64b5f6") | |
.setStroke("null"); | |
circularGauge.getMarker() | |
.setSize(7) | |
.setRadius(80); | |
circularGauge.getLabel(0) | |
.setText("<span style=\"font-size: 25\">Wind Direction</span>") | |
.setUseHtml(true) | |
.setHAlign(TextHAlign.CENTER); | |
circularGauge.getLabel(0) | |
.setAnchor(EnumsAnchor.CENTER_TOP) | |
.setOffsetY(50) | |
.setPadding(15, 20, 0, 0); | |
circularGauge.getLabel(1) | |
.setText("<span style=\"font-size: 20\">18.1</span>") | |
.setUseHtml(true) | |
.setHAlign(TextHAlign.CENTER); | |
circularGauge.getLabel(1) | |
.setAnchor(EnumsAnchor.CENTER_TOP) | |
.setOffsetY(-20) | |
.setPadding(5, 10, 0, 0) | |
.setBackground("{fill: 'none', stroke: '#c1c1c1', corners: 3, cornerType: 'ROUND'}"); | |
anyChartView.setChart(circularGauge); | |
} | |
} |
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 WindSpeedActivity 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)); | |
CircularGauge circularGauge = AnyChart.circular(); | |
circularGauge.setFill("#fff") | |
.setStroke(null) | |
.setPadding(0, 0, 0, 0) | |
.setMargin(30, 30, 30, 30); | |
circularGauge.setStartAngle(0) | |
.setSweepAngle(360); | |
double currentValue = 13.8D; | |
circularGauge.setData(new SingleValueDataSet(new Double[] { currentValue })); | |
circularGauge.getAxis() | |
.setStartAngle(-150) | |
.setRadius(80) | |
.setSweepAngle(300) | |
.setWidth(3) | |
.setTicks("{ type: 'line', length: 4, position: 'outside' }"); | |
circularGauge.getAxis().getLabels().setPosition("outside"); | |
circularGauge.getAxis().getScale() | |
.setMinimum(0) | |
.setMaximum(140); | |
circularGauge.getAxis().getScale() | |
.setTicks("{interval: 10}") | |
.setMinorTicks("{interval: 10}"); | |
circularGauge.getNeedle().setStroke(null); | |
circularGauge.getNeedle() | |
.setStartRadius("6%") | |
.setEndRadius("38%") | |
.setStartWidth("2%") | |
.setEndWidth(0); | |
circularGauge.getCap() | |
.setRadius("4%") | |
.setEnabled(true); | |
circularGauge.getCap().setStroke(null); | |
circularGauge.getLabel(0) | |
.setText("<span style=\"font-size: 25\">Wind Speed</span>") | |
.setUseHtml(true) | |
.setHAlign(TextHAlign.CENTER); | |
circularGauge.getLabel(0) | |
.setAnchor(EnumsAnchor.CENTER_TOP) | |
.setOffsetY(100) | |
.setPadding(15, 20, 0, 0); | |
circularGauge.getLabel(1) | |
.setText("<span style=\"font-size: 20\">" + currentValue + "</span>") | |
.setUseHtml(true) | |
.setHAlign(TextHAlign.CENTER); | |
circularGauge.getLabel(1) | |
.setAnchor(EnumsAnchor.CENTER_TOP) | |
.setOffsetY(-100) | |
.setPadding(5, 10, 0, 0) | |
.setBackground("{fill: 'none', stroke: '#c1c1c1', corners: 3, cornerType: 'ROUND'}"); | |
circularGauge.setRange(0, | |
"{\n" + | |
" from: 0,\n" + | |
" to: 25,\n" + | |
" position: 'inside',\n" + | |
" fill: 'green 0.5',\n" + | |
" stroke: '1 #000',\n" + | |
" startSize: 6,\n" + | |
" endSize: 6,\n" + | |
" radius: 80,\n" + | |
" zIndex: 1\n" + | |
" }"); | |
circularGauge.setRange(1, | |
"{\n" + | |
" from: 80,\n" + | |
" to: 140,\n" + | |
" position: 'inside',\n" + | |
" fill: 'red 0.5',\n" + | |
" stroke: '1 #000',\n" + | |
" startSize: 6,\n" + | |
" endSize: 6,\n" + | |
" radius: 80,\n" + | |
" zIndex: 1\n" + | |
" }"); | |
anyChartView.setChart(circularGauge); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment