gpt4 book ai didi

java - Android achartengine : Cannot draw multiple lines in a graph

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:40 24 4
gpt4 key购买 nike

我正在根据用户输入的方程在图表上绘制线条。如果用户输入多行,则无法绘制线条。

这是我的代码:

public void drawGraph(View v) {
EditText target = (EditText) findViewById(R.id.textView);
String equation = target.getText().toString();

mRenderer = new XYMultipleSeriesRenderer();

if (!equation.isEmpty()) {
String[] sides = equation.split("=");
List<String> variables = new ArrayList<String>();
String tempString = "";

if (sides.length > 1) {
String rightSide = sides[1];
char[] rightSideCharacters = rightSide.toCharArray();

for (char c : rightSideCharacters) {
if (Character.isLetter(c)) {
tempString = String.valueOf(c);
variables.add(String.valueOf(c));
}
}

boolean duplicates = duplicates(variables);


if (duplicates == false) {
lines++;

seriesRenderer = new XYSeriesRenderer();
seriesRenderer.setLineWidth(2);
seriesRenderer.setColor(Color.rgb(143, 2, 2));
seriesRenderer.setDisplayBoundingPoints(true);
seriesRenderer.setPointStyle(PointStyle.CIRCLE);
seriesRenderer.setPointStrokeWidth(3);

seriesRenderer2 = new XYSeriesRenderer();
seriesRenderer.setLineWidth(2);
seriesRenderer.setColor(Color.rgb(61, 90, 238));
seriesRenderer.setDisplayBoundingPoints(true);
seriesRenderer.setPointStyle(PointStyle.CIRCLE);
seriesRenderer.setPointStrokeWidth(3);

if (lines == 1) {
mRenderer.addSeriesRenderer(seriesRenderer);
}
if (lines == 2) {
mRenderer.addSeriesRenderer(seriesRenderer);
mRenderer.addSeriesRenderer(seriesRenderer2);
}

// We want to avoid black border
mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00)); // transparent margins
mRenderer.setPanEnabled(false, false);
mRenderer.setYAxisMax(range);
mRenderer.setYAxisMin(-range);
mRenderer.setXAxisMax(range);
mRenderer.setXAxisMin(-range);
mRenderer.setShowGrid(true); // we show the grid

XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

String originalRight = rightSide;
//System.out.println(range);

for (double i = -range; i < range; i++) {
rightSide = rightSide.replaceAll(tempString, "(" + String.valueOf(i) + ")");
math.setVariable(tempString, i);
if (lines == 1) {
graph.add(i, math.evaluate(rightSide.substring(1)));
}
if (lines == 2) {
System.out.println(i + "," + math.evaluate(rightSide.substring(1)));
graph2.add(i, math.evaluate(rightSide.substring(1)));
}
rightSide = originalRight;
}

if (lines == 1) {
dataset.addSeries(graph);
}
if (lines == 2) {
dataset.addSeries(graph);
dataset.addSeries(graph2);
}

chartView = ChartFactory.getLineChartView(this, dataset, mRenderer);
//chartView.repaint();
LinearLayout layout = (LinearLayout) findViewById(R.id.chartlayout);
layout.addView(chartView);
}
}
}
}

最佳答案

                seriesRenderer2 = new XYSeriesRenderer();
seriesRenderer.setLineWidth(2);
seriesRenderer.setColor(Color.rgb(61, 90, 238));
seriesRenderer.setDisplayBoundingPoints(true);
seriesRenderer.setPointStyle(PointStyle.CIRCLE);
seriesRenderer.setPointStrokeWidth(3);

应该有seriesRenderer2.setLineWidth(2);

关于java - Android achartengine : Cannot draw multiple lines in a graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728154/

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