问题
i have a little Problem with my combined chart. 3 years ago i made the same with Eclipse and used a jar library. I copied my code to android Studio, using a dependency and now it's not working. I can't get it work.
I will post my whole code and then I will mark the problem.
public void createChart()
{
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
final Bundle extras = this.getIntent().getExtras();
couchdurations = extras.getLongArray("couchtimes");
perstdurations = extras.getLongArray("persttimes");
//ToDo Sqlite noch ergänzen
XYSeries couchseries = new XYSeries("CouchBase");
XYSeriesRenderer couchRenderer = new XYSeriesRenderer();
XYSeries perstseries = new XYSeries("PerstDB");
XYSeriesRenderer perstRenderer = new XYSeriesRenderer();
couchRenderer.setColor(Color.RED);
couchRenderer.setPointStyle(PointStyle.X);
couchRenderer.setFillPoints(false);
couchRenderer.setLineWidth(2);
couchRenderer.setDisplayChartValues(false);
perstRenderer.setColor(Color.BLUE);
perstRenderer.setPointStyle(PointStyle.X);
perstRenderer.setFillPoints(false);
perstRenderer.setLineWidth(2);
perstRenderer.setDisplayChartValues(false);
multiRenderer.addSeriesRenderer(couchRenderer);
multiRenderer.addSeriesRenderer(perstRenderer);
multiRenderer.setYAxisMin(0.0);
multiRenderer.setYAxisMax(10000000.0);
multiRenderer.setXAxisMax(60000.0);
multiRenderer.setLabelsTextSize(40);
multiRenderer.setLegendTextSize(40);
for(int i = 0; i < couchdurations.length; i++)
{
couchseries.add(couchdurations[i], datasizes[i]);
perstseries.add(perstdurations[i], datasizes[i]);
}
dataset.addSeries(couchseries);
dataset.addSeries(perstseries);
// Getting a reference to LinearLayout of the MainActivity Layout
LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
// Specifying chart types to be drawn in the graph
// Number of data series and number of types should be same
// Order of data series and chart type will be same
String[] types = new String[dataset.getSeriesCount()];
for(int i = 0; i < (dataset.getSeriesCount()); i++)
{
types[i] = LineChart.TYPE;
}
// Creating a combined chart with the chart types specified in types array
mChart = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset, multiRenderer, types);
// Adding the Combined Chart to the LinearLayout
chartContainer.addView(mChart);
}
The problem is the following line:
mChart = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset, multiRenderer, types);
I always get the error that the 4th parameter is wrong. But I used originally the same code before 3 years inside another android app. Error Screenshot 1 Error Screenshot 2 You can see the Error Message in the attached pictures. Wrong 4th parameter type. Found 'java.lang.String[]', required: 'org.achartengine.chart.CombinedXYChart.XYCombinedChartDef[]'
Can anybody help me to solve this problem? I have no idea how to solve it.
回答1:
I got it. Changing from
String[] types = new String[dataset.getSeriesCount()];
for(int i = 0; i < (dataset.getSeriesCount()); i++)
{
types[i] = LineChart.TYPE;
}
to
CombinedXYChart.XYCombinedChartDef[] types = new CombinedXYChart.XYCombinedChartDef[]
{
new CombinedXYChart.XYCombinedChartDef(LineChart.TYPE, 0), new CombinedXYChart.XYCombinedChartDef(LineChart.TYPE, 1)
};
来源:https://stackoverflow.com/questions/35082161/achartengine-combinedxychart-wrong-4th-parameter-found