This is a migrated thread and some comments may be shown as answers.

Change Axis color and axis Lable color

5 Answers 104 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lakshan
Top achievements
Rank 1
Lakshan asked on 15 Jan 2016, 05:41 PM

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

Sort by
0
Lakshan
Top achievements
Rank 1
answered on 19 Jan 2016, 08:49 AM
Hello admin can you help me.
0
Todor
Telerik team
answered on 20 Jan 2016, 03:03 PM
Hi Lakshan,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Lakshan
Top achievements
Rank 1
answered on 25 Jan 2016, 05:17 AM

Thanks a lot Admin.It works for me.

 

And I want to know can we apply gradient to fillcolor of graph and StrokeColor.

0
Lakshan
Top achievements
Rank 1
answered on 26 Jan 2016, 05:48 AM

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);
    }
}

But i cant understand how can i apply this code to my above code Please help.
0
Todor
Telerik team
answered on 28 Jan 2016, 12:04 PM
Hello Lakshan,

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 {
with:
public class CustomSplineAreaSeries extends SplineAreaSeries {

2) In your code from your earlier post replace:
SplineAreaSeries splineAreaSeries = new SplineAreaSeries();
with:
CustomSplineAreaSeries splineAreaSeries = new CustomSplineAreaSeries();

I hope this information helps.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Lakshan
Top achievements
Rank 1
Answers by
Lakshan
Top achievements
Rank 1
Todor
Telerik team
Share this question
or