I tried to change axis color and axis lable colors and area color.But nothing happen.Please help me.
This is my code
RadCartesianChartView chartView = new RadCartesianChartView(this);
SplineAreaSeries splineAreaSeries = new SplineAreaSeries();
splineAreaSeries.setCategoryBinding(new PropertyNameDataPointBinding("Month"));
splineAreaSeries.setValueBinding(new PropertyNameDataPointBinding("Result"));
splineAreaSeries.setData(this.monthResults);
splineAreaSeries.setFillColor(getResources().getColor(R.color.colorAccent));//try to change fill color
CategoricalAxis horizontalAxis = new CategoricalAxis();
horizontalAxis.setLabelTextColor(Color.parseColor("#ffffff"));//axis lable colors
chartView.setHorizontalAxis(horizontalAxis);
LinearAxis verticalAxis = new LinearAxis();
verticalAxis.setLabelTextColor(Color.parseColor("#ffffff"));//axis lable colors
chartView.setVerticalAxis(verticalAxis);
chartView.getSeries().add(splineAreaSeries);
ViewGroup rootView = (ViewGroup)findViewById(R.id.spline_area_container);
rootView.addView(chartView);
5 Answers, 1 is accepted
Thank you for your question.
In order to provide default styles for the different types of axes, series, etc. Chart for Android uses Palettes. This means that unless otherwise specified the chart will use its palette for the colors and ignore the values that you have set. You have two options to change the colors:
1) use the respective properties, after you call setCanApplyPalette(false), which will prevent the usage of the default palette for the specified element, for example:
splineAreaSeries.setCanApplyPalette(
false
);
splineAreaSeries.setFillColor(getResources().getColor(R.color.colorAccent));
Since this will result in loosing some other values that you would have taken from the palette, I suggest the second approach:
2) clone the palette and change only the values that you are interested in:
ChartPalette customPalette = chart.getPalette().clone();
PaletteEntry areaEntry = customPalette.getEntry(ChartPalette.AREA_FAMILY);
areaEntry.setFill(Color.RED);
PaletteEntry hAxisEntry = customPalette.getEntry(ChartPalette.HORIZONTAL_AXIS_FAMILY);
hAxisEntry.setCustomValue(Axis.LABEL_COLOR,
"#00cccc"
);
PaletteEntry vAxisEntry = customPalette.getEntry(ChartPalette.VERTICAL_AXIS_FAMILY);
vAxisEntry.setCustomValue(Axis.LABEL_COLOR,
"#00cccc"
);
chart.setPalette(customPalette);
There is no need to change the colors of your spline area series object, if you have modified the palette that it uses. You can read more about the usage of palettes in the chart in our online documentation.
I hope this information helps. Let us know if you need further assistance.
Regards,
Todor
Telerik
Thanks a lot Admin.It works for me.
And I want to know can we apply gradient to fillcolor of graph and StrokeColor.
I saw there's a answer from you how to apply gradient colors to area
public class CustomAreaSeries extends AreaSeries {
@Override
public void render(Canvas canvas) {
Paint paint = new Paint();
RectF plotArea = Util.convertToRectF(this.chart.getPlotAreaClip());
paint.setShader(new LinearGradient(plotArea.left,
plotArea.centerY(), plotArea.right, plotArea.centerY(), Color.RED,
Color.GREEN, Shader.TileMode.CLAMP));
AreaRendererBase renderer = (AreaRendererBase)this.getRenderer();
renderer.setFillPaint(paint);
super.render(canvas);
}
}
You can extend directly the SplineAreaSeries instead of AreaSeries and simply use instance of the new class instead of the original. This means:
1) In the code from the previous post replace:
public
class
CustomAreaSeries extends AreaSeries {
public
class
CustomSplineAreaSeries extends SplineAreaSeries {
2) In your code from your earlier post replace:
SplineAreaSeries splineAreaSeries =
new
SplineAreaSeries();
CustomSplineAreaSeries splineAreaSeries =
new
CustomSplineAreaSeries();
I hope this information helps.
Regards,
Todor
Telerik