Anychart Android polar plot xAxis labels change them to char strings - android

Good morning,
I was trying to implement an AnyChart polar plot in android (https://github.com/AnyChart/AnyChart-Android) which should look something similar to this (https://playground.anychart.com/gallery/Polar_Charts/Line_Polar_Chart). I know this example is in javascript and I am developping it within Android, which is not exactly the same, but to keep a reference of the result I want to achieve is fine.
From that example, I have been struggling to change the xAxis Labels (0°, 30°, ...) to custom made strings, such as ("Zero", "Thirty",...).
I didn't manage to find a xAxis label getter which returns the label string (https://api.anychart.com/v8/anychart.core.ui.LabelsFactory#getLabel) but haven't been able to find a label setter...
My aim would be to keep the numerical functionallity of a Anychart polar plot, where a line could be plotted from (45°, value 1) to (45°, value 5) and having displayed chars at the xlabel of the plot, so instead of seeing "45°" to the label, it should say "fourty-five"
Do anyone have any idea if this is achievable?
Thank you very much!

You can achieve that using format() function of the xAxis labels. In the callback function you can implement your own logic on how to translate numbers to words (if, case, hashmap, etc). The snippet describes how to achieve that.
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
Polar polar = AnyChart.polar();
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry(0, 10));
data.add(new ValueDataEntry(15, 8));
data.add(new ValueDataEntry(30, 12));
data.add(new ValueDataEntry(45, 11));
Set set = Set.instantiate();
set.data(data);
Mapping series1Data = set.mapAs("{ x: 'x', value: 'value' }");
polar.line(series1Data);
Linear scale = Linear.instantiate();
scale.minimum(0).maximum(360);
scale.ticks().interval(30);
polar.xScale(scale);
polar.xAxis().labels().format("function() {" +
"if (this.tickValue == 60) return 'sixty';" +
"if (this.tickValue == 90) return 'ninety';" +
"if (this.tickValue == 120) return 'hundred twenty';" +
"return this.tickValue;" +
"}");
anyChartView.setChart(polar);
Below is the result:

Related

Show integer values instead of decimal in MPAndroidChart by PhilJay?

I'm using MPAndroidChart for showing hours of work by day.
Everything is working fine, but I can't figure out how to show integer, not float. For example, if I insert 19 hours in chart, it's showing like this at the top of each chart. Can I show it like 19 h?
Set value formatter, If you set 0 in DefaultValueFormatter it will be shown like integer value example 25, if you set 1 now the output will be 25.0
val barDataSet = BarDataSet(entries, "")
barDataSet.valueFormatter = DefaultValueFormatter(0)
Set value Formatter
val xAxis = barChart.xAxis
xAxis.valueFormatter = IAxisValueFormatter { value, axis -> value.roundToInt() }

Custom x-axis labelling in MPAndroid Chart

I want the x-axis labelling to be as shown in the above picture. I have tried using the AxisValueFormatter interface but what it does is repeat the label 'jh ow' 3 times from 0 to 1, while missing out some of the labels shown here.
This is the output I am getting. While the shape of the graph is correct, the labels are not.
I am sharing the graph data so that anyone interested can try and make the graph as shown. Any help would be great, thank you.
Using MPAndroid is not important. Any help from any other library is fine too.
The data are:
"lables" : ["jh ow", "n ih l", "b iy", "hh iy r", "s uw n"]
"values":[[{"x":"0.00","y":"0.00"},{"x":"0.99","y":"0.00"}],
[{"x":"0.99","y":"1.00"},{"x":"1.19","y":"0.50"}]
, [{"x":"1.19","y":"0.50"},{"x":"1.37","y":"0.50"}]
, [{"x":"1.37","y":"0.50"},{"x":"1.59","y":"0.50"}]
, [{"x":"1.59","y":"0.50"},{"x":"2.12","y":"1.00"}]]
You just make a simple list of string like this in activity page;
final ArrayList<String> xVals= new ArrayList<>();
xVals.add("jh ow");
xVals.add("n ih l");
xVals.add("b iy");
xVals.add("hh iy r");
xVals.add("s uw n");
and Then you do this;
xAxis.setValueFormatter(new MyXAxisDateArrayFormatter(xVals));
your MyXAxisDateArrayFormatter.java
public class MyXAxisDateArrayFormatter implements IAxisValueFormatter {
private String[] mValues;
public MyXAxisDateArrayFormatter(String[] values) {
this.mValues = values;
}
#Override
public String getFormattedValue(float value, AxisBase axis) {
// "value" represents the position of the label on the axis (x or y)
return mValues[(int) value];
}
}
It worked on me
Nevermind, I was able to achieve this by using an older version of MPAndroidChart library and it worked like a charm.

Charts - using Mp Chart

I need to draw graph like the image i have uploaded , i am using MP chart library and develop a graph but want to customize it according to my requirement but not able to find solution for my requirements my basic requirement is for x axis i want to show custom values at axis like 5-11 12-18 but i am passing value to x axis like this
private ArrayList<String> setXAxisValues() {
ArrayList<String> xVals = new ArrayList<String>();
xVals.add("10");
xVals.add("20");
xVals.add("30");
xVals.add("30.5");
xVals.add("40");
return xVals;
}
So it is showing x values like this 10 20 30 so on so i want my graph to be built upon using these x value which is happening right now but want to show custom value at bottom like 5-11 etc and this value is dynamic coming from Api response so please help me about this , Waiting for positive and early response Thanks in Advance
To format the x-axis values, you should use the setValueFormatter method which takes a callback interface were you have to implement the getFormattedValue method which is called before drawing the x-axis value.
xAxis.setValueFormatter((value, axis) -> {
String res = "";
try {
// get current position of x-axis
int currentPosition = (int) value;
// check if position between array bounds
if (currentPosition > -1 && currentPosition < maxSize) {
// get value from formatted values array
res = xVals.get(currentPosition);
}
} catch (Exception e) {
// handle exception
}
return res;
});

Query between distances in Parse

I would like to search places between two given distances, using GeoPoints. Using the currently api, I think I could make something like this pseudo algorithm:
query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MAXIMUM distance);
MINUS
query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MINIMUM distance);
How can I translate to real code?
Finally I found a way to do it with a parse query.
// Do not want locations further than maxDistance
ParseQuery query = ParseQuery.getQuery("MyData");
query.whereWithinKilometers("location", userGeoPoint, maxDistance);
// Do not want locations closer than minDistance
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("MyData");
innerQuery.whereWithinKilometers("location", userGeoPoint, minDistance);
query.whereDoesNotMatchKeyInQuery("objectId", "objectId", innerQuery);
Likely you'll have to pull in everything within the maximum distance from Parse to your app, then inside your app filter out anything that is closer than the minimum.
Thankfully Parse includes some distance measuring as part of PFGeoPoint. Check out the three methods here.
distanceInRadiansTo:
distanceInMilesTo:
distanceInKilometersTo:
So your pseudocode is:
(After you get back everything within the outer radius)
Make a new array (var) called finalList
For i = 0; i < objects.count; i++ {
var gp: PFGeoPoint = objects[i]
if gp.distanceInMilesTo:originalGeoPoint >= minimumRadiusInMiles {
finalList.push(gp)
}
}

How to Change the X-axis using Graph View Demo in android

Basically i want to draw a graph where x-axis gives you the date and y axis gives u the count
I am getting data from server and parsing it in my two array's one is for count and other is for date
i am getting values in two array like this
SoapObject o=(SoapObject)p2.getProperty(xx);
UserCallStatusBean ld=new UserCallStatusBean();
if(o.getProperty("Month").toString().equals("anyType{}")){
ld.setDuration("");
}
else{
ld.setDuration(o.getProperty("Month").toString());
}
ld.setCount(Integer.parseInt(o.getProperty("Count").toString()));
CallStatus.add(ld);
GraphViewData o1=new GraphViewData(_iLoopCounter,Double.parseDouble(o.getProperty("Count").toString()));
String o2=new String(o.getProperty("Month").toString());
//String o2=new String(String.valueOf(_iLoopCounter));
arrData[xx]=o1;
arrXaxis[xx]=o2;
_iLoopCounter++;
After Getting the Value in two array i use Graph View Demo to create a grapg like
setContentView(R.layout.graphs);
// init example series data
exampleSeries = new GraphViewSeries(arrData);
// graph with dynamically genereated horizontal and vertical labels
GraphView graphView;
graphView = new BarGraphView(
this,"");
graphView.addSeries(exampleSeries); // data
graphView.setScalable(true);
graphView.setScrollable(true);
graphView.setViewPort(2,6);
graphView.setScrollable(true);
graphView.setHorizontalLabels(arrXaxis);
graphView.setGravity(Gravity.CENTER);
graphView.setBaselineAlignedChildIndex(4);
//graphView.setHorizontalLabels(labels);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
Now My issue of concern is i am getting value of count on y-axis but i am also getting count of date on x-axis instead i want to show the date on x-axis
I Have read various articles to get string value on x-axis ,finded one to use Cutom lavel formatter , But didnt knw how to use so what i can do to get x-axis ? (Date Value)
I hope u understands ,Expecting Answer Pleasue will b aLl Mine
Thanks in advance

Categories

Resources