I'm trying to construct a linearColorScale of AnyChart, and I've tried the code below but haven't gotten any results. Please let me know if there is a bug in this code or if I am missing something.
P.S. As said, I modified minSDK 19 and followed the documentation. Please let me know if there is anything I'm missing:)
TIA.
public class GeneralFragment extends Fragment {
AnyChartView daysScale;
private View view;
private LineChart symbolDetailChart;
private ArrayList<Entry> values;
private LineDataSet set1;
private LineData data;
private Drawable drawablePositive = ContextCompat.getDrawable(Logs.globalContext, R.drawable.graph_green_bg);
public GeneralFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_general, container, false);
daysScale = view.findViewById(R.id.scalechartdays);
LinearGauge linearGauge = AnyChart.linear();
linearGauge.data(new SingleValueDataSet(new Double[] { 5.3D }));
linearGauge.layout(Layout.HORIZONTAL);
linearGauge.label(0)
.position(Position.LEFT_CENTER)
.anchor(Anchor.LEFT_CENTER)
.offsetY("-50px")
.offsetX("50px")
.fontColor("black")
.fontSize(17);
linearGauge.label(0).text("Total Rainfall");
linearGauge.label(1)
.position(Position.LEFT_CENTER)
.anchor(Anchor.LEFT_CENTER)
.offsetY("40px")
.offsetX("50px")
.fontColor("#777777")
.fontSize(17);
linearGauge.label(1).text("Drought Hazard");
linearGauge.label(2)
.position(Position.RIGHT_CENTER)
.anchor(Anchor.RIGHT_CENTER)
.offsetY("40px")
.offsetX("50px")
.fontColor("#777777")
.fontSize(17);
linearGauge.label(2).text("Flood Hazard");
OrdinalColor scaleBarColorScale = OrdinalColor.instantiate();
scaleBarColorScale.ranges(new String[]{
"{ from: 0, to: 2, color: ['red 0.5'] }",
"{ from: 2, to: 3, color: ['yellow 0.5'] }",
"{ from: 3, to: 7, color: ['green 0.5'] }",
"{ from: 7, to: 8, color: ['yellow 0.5'] }",
"{ from: 8, to: 10, color: ['red 0.5'] }"
});
linearGauge.scaleBar(0)
.width("5%")
.colorScale(scaleBarColorScale);
linearGauge.marker(0)
.type(MarkerType.TRIANGLE_DOWN)
.color("red")
.offset("-3.5%")
.zIndex(10);
linearGauge.scale()
.minimum(0)
.maximum(10);
// linearGauge.scale().ticks
linearGauge.axis(0)
.minorTicks(false)
.width("1%");
linearGauge.axis(0)
.offset("-1.5%")
.orientation(Orientation.TOP)
.labels("top");
linearGauge.padding(0, 30, 0, 30);
daysScale.setChart(linearGauge);
return view;
}
}
The chart configuration code is absolutely ok. Below is the working code and the resulting chart. You should check errors and debug the rest of your code.