gpt4 book ai didi

java - achartengine 两行有 2 个 y 轴和 1 个 x 轴 -> 第二行不适合

转载 作者:行者123 更新时间:2023-12-01 04:42:15 26 4
gpt4 key购买 nike

我试图在一个线图中绘制两条线,其中有两个 y 轴和 1 个 x 轴。第一行是正确的,但第二行不适合 x 值。

目前看起来像这样:

enter image description here

这是代码:

bmiSeries =  new XYSeries("BMI",0);
bmiSeries2 = new XYSeries("BMI Trefethen",1);

dataset = new XYMultipleSeriesDataset();

bmiRenderer = new XYSeriesRenderer();
bmiRenderer.setColor(getResources().getColor(R.color.green));
bmiRenderer.setPointStyle(PointStyle.CIRCLE);
bmiRenderer.setFillPoints(true);
bmiRenderer.setLineWidth(2);
bmiRenderer.setDisplayChartValues(true);

bmiRenderer2 = new XYSeriesRenderer();
bmiRenderer2.setColor(getResources().getColor(R.color.red));
bmiRenderer2.setPointStyle(PointStyle.CIRCLE);
bmiRenderer2.setFillPoints(true);
bmiRenderer2.setLineWidth(2);
bmiRenderer2.setDisplayChartValues(true);



multiRenderer = new XYMultipleSeriesRenderer(2);
multiRenderer.setXLabels(0);
multiRenderer.setZoomButtonsVisible(true);
multiRenderer.setMargins(new int[] {0, 25 ,25,25});

for(int i=0; i<bmiList.size();i++){
bmiSeries.add(i, bmiList.get(i).getBmi_old());
bmiSeries2.add(i, bmiList.get(i).getBmi_new());
Date dat = bmiList.get(i).getDate();
Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = formatter.format(dat);
multiRenderer.addXTextLabel(i, date);
}


dataset.addSeries(0, bmiSeries);
dataset.addSeries(1, bmiSeries2);

multiRenderer.addSeriesRenderer(bmiRenderer);
multiRenderer.addSeriesRenderer(bmiRenderer2);
multiRenderer.setBarSpacing(4);
multiRenderer.setApplyBackgroundColor(true);
multiRenderer.setBackgroundColor(Color.argb(0x00, 0x01, 0x01, 0x01));
multiRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
multiRenderer.setYLabelsColor(0, Color.BLACK);
multiRenderer.setXLabelsColor(Color.BLACK);
multiRenderer.setShowGrid(true);
multiRenderer.setZoomEnabled(true, false);
multiRenderer.setXTitle("Date");
multiRenderer.setYTitle("BMI");
multiRenderer.setLabelsTextSize(15);
multiRenderer.setXAxisMin(-1);
multiRenderer.setXAxisMax(2);
multiRenderer.setYAxisMin(bmiSeries.getMinY()-5,0);
multiRenderer.setYAxisMax(bmiSeries.getMaxY()+3,0);
multiRenderer.setYAxisMin(bmiSeries2.getMinY()-5,1);
multiRenderer.setYAxisMax(bmiSeries2.getMaxY()+3,1);
multiRenderer.setYAxisAlign(Align.RIGHT, 0);
multiRenderer.setPanEnabled(true, false);
multiRenderer.setChartValuesTextSize(10);
multiRenderer.setZoomLimits(new double[] {-2,10,0,10});
multiRenderer.setPanLimits(new double[] { bmiSeries.getMinX()-1, bmiSeries.getMaxX()+10, bmiSeries.getMinY(), bmiSeries.getMaxY() });

LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
ZoomListener listener = new ZoomListener() {
@Override
public void zoomReset() {
zoomR = 1;
multiRenderer.setChartValuesTextSize(10*zoomR);
multiRenderer.setLabelsTextSize(15);

}

@Override
public void zoomApplied(ZoomEvent e) {
if(e.isZoomIn()){
zoomR += 0.3;
}
else{
zoomR -= 0.3;
}
multiRenderer.setChartValuesTextSize(10*zoomR);
multiRenderer.setLabelsTextSize(15*zoomR);

}
};

mChart = (GraphicalView) ChartFactory.getLineChartView(getBaseContext(), dataset, multiRenderer);
mChart.addZoomListener(listener, true, true);
chartContainer.addView(mChart);

希望有人能帮助我

最佳答案

问题是您仅为第一个比例设置 X 轴范围。因此,您可以删除 setXAxis* 调用,或者为您拥有的第二个比例添加类似的调用:

multiRenderer.setXAxisMin(-1, 1);
multiRenderer.setXAxisMax(2, 1);

关于java - achartengine 两行有 2 个 y 轴和 1 个 x 轴 -> 第二行不适合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16344118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com