gpt4 book ai didi

java - 如何使用 AChartEngine 绘制双 Y 轴(辅助 Y 轴) - Android

转载 作者:行者123 更新时间:2023-12-01 04:28:09 24 4
gpt4 key购买 nike

我有两个数据系列,其中有两个不同的 Y 轴和一个 X 轴。我正在尝试绘制双 Y 轴(或在 Excel 中称为辅助 Y 轴),以便缩放图表。但我只得到两个数据系列的单个 Y 轴。注意:我使用的是 AChartEngine 1.1.0

谁能指点一下。

下面给出了我的代码和屏幕截图。

public class LineChart {
public Intent getIntent(Context context){

int[] x = {1,2,3,4,5,6,7,8,9,10};
int[] y = {22,45,34,45,55,65,74,85,93,100};

TimeSeries series = new TimeSeries("Data1");
for(int i = 0; i<x.length; i++){
series.add(x[i], y[i]);
}

int[] x2 = {1,2,3,4,5,6,7,8,9,10};
int[] y2 = {223,454,334,454,554,655,745,855,935,510};

TimeSeries series2 = new TimeSeries("Data2");
for(int i = 0; i<x.length; i++){
series2.add(x2[i], y2[i]);
}


//Multiple Series Data Set
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series); //First Data Series
dataset.addSeries(series2); //Second Data Series

//Multiple Series Renderer
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(2);
//Background
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.BLACK);
//mRenderer.setMarginsColor(Color.parseColor("#F5F5F5"));
//Grid
mRenderer.setShowGridY(true);
mRenderer.setShowGridX(true);
mRenderer.setGridColor(Color.WHITE);
//Label
mRenderer.setLabelsTextSize(14);
mRenderer.setXLabelsColor(Color.GREEN);
//Min and Max
mRenderer.setXAxisMax(series.getMaxX());
mRenderer.setXAxisMin(series.getMinX());

//Dual yaxis
mRenderer.setYLabelsColor(0, Color.GREEN);
mRenderer.setYLabelsColor(1, Color.RED);
mRenderer.setYTitle("Y-AXIS1", 0);
mRenderer.setYTitle("Y-AXIS2", 1);
mRenderer.setYAxisAlign(Align.LEFT, 0);
mRenderer.setYAxisAlign(Align.RIGHT, 1);
mRenderer.setYLabelsAlign(Align.LEFT, 0);
mRenderer.setYLabelsAlign(Align.RIGHT, 1);


//First Series - Single Series Renderer
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);

//Second Series - Single Series Renderer
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.GREEN);
renderer2.setPointStyle(PointStyle.CIRCLE);
renderer2.setFillPoints(true);

//Add renderers to multiple series Renderer
mRenderer.addSeriesRenderer(renderer);
mRenderer.addSeriesRenderer(renderer2);


Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph Title");

return intent;
}

}

Screenshot Here

最佳答案

最后,我使用这个示例完成了它 - here

关于java - 如何使用 AChartEngine 绘制双 Y 轴(辅助 Y 轴) - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18282563/

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