Reputation: 231
I am using Achartengine for LineChart. I already added line color for XYSeriesRenderer object. I am getting dynamic values from a library to draw chart. If x value reached maximum, I need to change the color of line chart. I am using only one series. I tried and I couldn't. Is there any way to change line color dynamically?
Upvotes: 1
Views: 2530
Reputation: 26
// Declaring and instantiating objects:
XYMultipleSeriesRenderer mTimeRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer mCurrentRenderer = new XYSeriesRenderer();
// Defining XYRenderer properties
mCurrentRenderer.setColor(Color.CYAN);
// Associating XYRenderer to the XYMultipleSeriesRenderer
mTimeRenderer.addSeriesRenderer(mCurrentRenderer);
//{...}
// You could get your XYRenderer later on with:
mCurrentRenderer = mTimeRenderer.getSeriesRendererAt(0);
Of course, you could repaint dynamically your chart and change your renderer properties at any time.
Explanation:
XYSeriesRenderer
objects are used as XYRenderer
containers.
The way you set your line color is using the XYRenderer.setColor(int color)
method.
You might get your current renderer calling getSeriesRendererAt(int index)
over your XYSeriesRenderer
or you might already have a XYRenderer
object to interact with.
Upvotes: 1
Reputation: 32391
Just change the color this way:
renderer.setColor(newColor);
And then repaint the chart:
chartView.repaint();
Upvotes: 0