我正在尝试构造一个AnyChart的linearColorScale,我已经尝试了下面的代码,但是没有得到任何结果。如果这段代码中有bug或者我遗漏了什么,请让我知道。
附注:如上所述,我修改了minSDK 19并遵循了文档。如果我遗漏了什么,请告诉我:)
蒂娅。
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;
}
}发布于 2021-11-02 05:02:42
图表配置代码完全正确。下面是工作代码和结果图表。您应该检查错误并调试代码的其余部分。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
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);
anyChartView.setChart(linearGauge);
}

https://stackoverflow.com/questions/69789603
复制相似问题