Change Axis color and axis Lable color

6 posts, 0 answers
  1. Lakshan
    Lakshan avatar
    4 posts
    Member since:
    Jan 2016

    Posted 15 Jan Link to this post

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

  2. Lakshan
    Lakshan avatar
    4 posts
    Member since:
    Jan 2016

    Posted 19 Jan in reply to Lakshan Link to this post

    Hello admin can you help me.
  3. DevCraft banner
  4. Todor
    Admin
    Todor avatar
    778 posts

    Posted 20 Jan Link to this post

    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
  5. Lakshan
    Lakshan avatar
    4 posts
    Member since:
    Jan 2016

    Posted 24 Jan in reply to Todor Link to this post

    Thanks a lot Admin.It works for me.

     

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

  6. Lakshan
    Lakshan avatar
    4 posts
    Member since:
    Jan 2016

    Posted 25 Jan Link to this post

    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.
  7. Todor
    Admin
    Todor avatar
    778 posts

    Posted 28 Jan Link to this post

    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
Back to Top
DevCraft banner