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

Vertical Axis shows Decimal format values not integer

9 Answers 515 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.
Jake
Top achievements
Rank 1
Jake asked on 18 Aug 2014, 09:22 AM
Hi Team,

i am working on chart part and i want to show integer value in Y Axis or Vertical Axis like 1,2,3,4 not like decimal values 0.0,1.0, 2.0, 3.0.
here i have attached the code values please help me out for it. 


public FrameLayout barChartView(String strLegend, List<DashBoardCharts> chart)
    {

        try
        {
            if (chart != null)
            {

                radCartesianChartView = new RadCartesianChartView(activity);
                BarSeries barSeries = new BarSeries(activity);
                barSeries.setLegendTitle(strLegend);
                barSeries.setCombineMode(ChartSeriesCombineMode.CLUSTER);
                legendView = new RadLegendView(activity);
                legendView.setLegendProvider(radCartesianChartView);

                legendView.setX(50f);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(450,
                        100);

                params.setMargins(10, 0, 10, 10);

                legendView.setLayoutParams(params);

                barSeries.setCategoryBinding(new DataPointBinding()
                {
                    @Override
                    public Object getValue(Object o)
                    {
                        return ((Dashboard.DashBoardCharts) o).getCategory();
                    }
                });
                barSeries.setValueBinding(new DataPointBinding()
                {
                    @Override
                    public Object getValue(Object o)
                    {
                        return ((Dashboard.DashBoardCharts) o).getValue();
                    }
                });

                barSeries.setData(chart);

                // ChartPalette customPalette = new ChartPalette();
                // PaletteEntryCollection collection = new PaletteEntryCollection();
                //
                // PaletteEntry entry =null;
                // collection.setFamily(barSeries.paletteFamily());
                // entry = new
                // PaletteEntry(Color.parseColor("#FF0079FF"));
                // collection.add(entry);
                // customPalette.seriesEntries().add(collection);
                // radCartesianChartView.setPalette(customPalette);

                radCartesianChartView.getSeries().add(barSeries);

                CategoricalAxis horizontalAxis = new CategoricalAxis(activity);
                radCartesianChartView.setHorizontalAxis(horizontalAxis);

                //horizontalAxis.setLabelFitMode(AxisLabelFitMode.ROTATE);

                LinearAxis verticalAxis = new LinearAxis(activity);
                //verticalAxis.setLabelFormat("");
                radCartesianChartView.setVerticalAxis(verticalAxis);

    
                
                ChartPanAndZoomBehavior behavior = new ChartPanAndZoomBehavior();

                behavior.setZoomMode(ChartPanZoomMode.VERTICAL);
                behavior.setPanMode(ChartPanZoomMode.BOTH);
                radCartesianChartView.getBehaviors().add(behavior);
                radCartesianChartView.getBehaviors().add(new ChartSelectionBehavior());

                radCartesianChartView.addView(legendView);
            }
        } catch (Exception e)
        {
            if (LogLevels.ERROR)
                Controller.logger.error(ErrorStackTraceUtil.getCombinedStackTrace(e));
            e.printStackTrace();
        }
        return radCartesianChartView;

    }


Regards,
jake

9 Answers, 1 is accepted

Sort by
0
Antony Jekov
Telerik team
answered on 19 Aug 2014, 08:32 AM
Hello Jake,

Thank you for contacting the Android team.

The values of the axes are being kept as doubles for precision purposes, but you have full control on the end result. All you need to do is provide a custom value-to-string converter function.
Here is an example regarding your question:
verticalAxis.setLabelValueToStringConverter(new Function<Object, String>() {
    @Override
    public String apply(Object argument) {
        return String.valueOf((int)((MajorTickModel) argument).value());
    }
});

This will make all the values for the axis integers before turning them to strings. I hope this answers your question. Please feel free to add to this ticket or start a new one should you have any additional problems.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jake
Top achievements
Rank 1
answered on 19 Aug 2014, 12:23 PM
hi,

thank you so much , it works fine.
0
Antony Jekov
Telerik team
answered on 21 Aug 2014, 07:13 AM
Hello Jake,

I am glad to hear it. I will proceed and close this ticket. Please feel free to reopen it at any time.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Thanh
Top achievements
Rank 1
answered on 04 Sep 2014, 07:44 AM
tks you!
0
Richard
Top achievements
Rank 1
answered on 12 May 2015, 03:54 PM

Isn't this what the setLabelFormat() function is supposed to do now? 

However, there is no documentation on what string values to use for formatting and "#" and "0" return the literal values not the number formatted that way.

0
Victor
Telerik team
answered on 14 May 2015, 10:30 AM
Hello Richard,

The label format is a standard java string format. You read more about it here.

Regards,
Victor
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
joe
Top achievements
Rank 1
answered on 12 Jun 2015, 06:56 AM
I think all you need to do is provide a custom value-to-string converter function.
0
joe
Top achievements
Rank 1
answered on 15 Jun 2015, 02:05 AM

And i have just try it...

[url=http://www.casesam.co.uk/category-galaxy-s6-edge-case-cover-10.html]Samsung Galaxy S6 edge cover[/url]

0
joe
Top achievements
Rank 1
answered on 15 Jun 2015, 02:06 AM

http://www.casesam.co.uk/category-galaxy-s6-edge-case-cover-10.html

http://www.casesam.co.uk

Tags
Chart
Asked by
Jake
Top achievements
Rank 1
Answers by
Antony Jekov
Telerik team
Jake
Top achievements
Rank 1
Thanh
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Victor
Telerik team
joe
Top achievements
Rank 1
Share this question
or