Skip to content

Instantly share code, notes, and snippets.

@ArsenyMalkov
Created July 20, 2018 04:10
Show Gist options
  • Save ArsenyMalkov/9bacd611298707dab5049ad8952e5b32 to your computer and use it in GitHub Desktop.
Save ArsenyMalkov/9bacd611298707dab5049ad8952e5b32 to your computer and use it in GitHub Desktop.
WindSpeed
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));
final 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);
final int delayMillis = 500;
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
public void run() {
double curentValue = new Random().nextDouble() * 140d;
circularGauge.setData(new SingleValueDataSet(new Double[] { curentValue }));
circularGauge.getLabel(1).setText("<span style=\"font-size: 20\">" + String.format(Locale.US, "%.1f", curentValue) + "</span>");
handler.postDelayed(this, delayMillis);
}
};
handler.postDelayed(runnable, delayMillis);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment