有没有办法将achartengine
折线图的线点颜色颜色从白色更改为黑色?
在下图中,我想将颜色2700,2500等从白色更改为黑色。
这是我的代码:
private void openChart() {
int count = 5;
Date[] dt = new Date[5];
for (int i = 0; i < count; i++) {
GregorianCalendar gc = new GregorianCalendar(2014, 10, i + 1);
dt[i] = gc.getTime();
}
int[] visits = {2000, 2500, 2700, 2100, 2800};
// Creating TimeSeries for Visits
TimeSeries visitsSeries = new TimeSeries("BMR Rate");
// Adding data to Visits Series
for (int i = 0; i < dt.length; i++)
visitsSeries.add(dt[i], visits[i]);
// Creating a dataset to hold each series
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
// Adding Visits Series to the dataset
dataset.addSeries(visitsSeries);
// Creating XYSeriesRenderer to customize visitsSeries
XYSeriesRenderer visitsRenderer = new XYSeriesRenderer();
visitsRenderer.setColor(Color.WHITE);
visitsRenderer.setPointStyle(PointStyle.SQUARE);
visitsRenderer.setFillPoints(true);
visitsRenderer.setLineWidth(3);
visitsRenderer.setDisplayChartValues(true);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setChartTitle("Body Mass Index");
// multiRenderer.setMargins(new int[]{0, 0, 0, 10});
multiRenderer.setApplyBackgroundColor(true);
// multiRenderer.setPointSize(15);
multiRenderer.setLabelsColor(Color.WHITE);
multiRenderer.setGridColor(Color.RED);
multiRenderer.setMarginsColor(Color.parseColor("#54D66A"));
multiRenderer.setYLabelsColor(0,Color.WHITE);
multiRenderer.setXLabelsColor(Color.WHITE);
multiRenderer.setXTitle("Days");
multiRenderer.setYTitle("Count");
multiRenderer.setZoomButtonsVisible(true);
// Adding visitsRenderer and viewsRenderer to multipleRenderer
// Note: The order of adding dataseries to dataset and renderers to multipleRenderer
// should be same
multiRenderer.addSeriesRenderer(visitsRenderer);
// multiRenderer.addSeriesRenderer(viewsRenderer);
// Getting a reference to LinearLayout of the MainActivity Layout
LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
// Creating a Time Chart
mChart = (GraphicalView) ChartFactory.getTimeChartView(getBaseContext(), dataset, multiRenderer, "dd-MMM-yyyy");
multiRenderer.setClickEnabled(true);
multiRenderer.setSelectableBuffer(10);
// Setting a click event listener for the graph
mChart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Format formatter = new SimpleDateFormat("dd-MM");
SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
int seriesIndex = seriesSelection.getSeriesIndex();
String selectedSeries = "Visits";
if (seriesIndex == 0)
selectedSeries = "Visits";
else
selectedSeries = "Views";
// Getting the clicked Date ( x value )
long clickedDateSeconds = (long) seriesSelection.getXValue();
Date clickedDate = new Date(clickedDateSeconds);
String strDate = formatter.format(clickedDate);
// Getting the y value
int amount = (int) seriesSelection.getValue();
// Displaying Toast Message
Toast.makeText(
getBaseContext(),
selectedSeries + " on " + strDate + " : " + amount ,
Toast.LENGTH_SHORT).show();
}
}
});
// Adding the Line Chart to the LinearLayout
chartContainer.addView(mChart);
}
答案 0 :(得分:0)
如果你想改变一个点的颜色,你可能需要对渲染器进行子类化,并在渲染该点时自己设置颜色。
答案 1 :(得分:0)
为渲染标签添加颜色:
multiRenderer.setYLabelsColor(0, Color.BLACK);
multiRenderer.setXLabelsColor(Color.BLACK);