Use images as data points in line graph - Android - java

I am new to Android Development and I have to make line graph.
The graph I am trying to make is very customized i.e. using images as the data point.
There are lots of open source libraries but I cant use images as data points and they should be clickable.
Chart I am trying to make

i'm to late in answering this question but i have done recently this type of work using MPChartAndroid
this is the simple code to set icons you can check complete example at this link
ArrayList<Entry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) - 30;
values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
}
LineDataSet set1;
set1 = LineDataSet(values, "")
set1.setDrawIcons(true)
chart.setData(data);

Related

Android - MPAndroid Chart showing x axis value

I have a listview with data in one activity and show that data in a graph in another activity. ListView Data. and displayed on graph.
I want to show the x axis associated with the value("Running", "Swimming")
I'm using an intent to send the value to the graph page and here is the code i'm using to populate the graph.
ArrayList<String> cardioValue = new ArrayList<String>();
ArrayList<String> cardioCategory = new ArrayList<String>();
cardioValue = intent.getStringArrayListExtra("cardioValue");
cardioCategory = intent.getStringArrayListExtra("cardioCategory");
ArrayList<BarEntry> barEntries = new ArrayList<>();
for(int i=0; i<cardioValue.size(); i++ ){
barEntries.add(new BarEntry( i+1, Integer.parseInt(cardioValue.get(i))));
}
You will have to use a value formatter to achieve this.
String[] cardioValue = {"", "Running, "Swimming"};
XAxis xaxis = mChart.getXAxis();
xaxis.setValueFormatter(new IndexAxisValueFormatter(cardioValue));
I have kept the first value of the string array empty because your first bar is being formed at value 1.
You will have to do the same with array lists.
Link to documentaion.
Working example.

Real time data to string/Data Point

I'm working on an Android project where the subject is to develop an android application to gather data from an external sensor (phidgets) and then generate a graphic representation using graphview or similar. The question i would like to expose is how to save the real time data to the DataPoint[] structure. I've tried with while and for methods using number of points or time.
DataPoint[] data_ax = new DataPoint[number of points];
data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);
or with a for cycle
DataPoint[] data_ax = new DataPoint[number of points];
for (int i = 0;i<30;i++){
data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);
}
while cycle
long t= System.currentTimeMillis();
long end = t+15000;//15*1000 seconds
while(System.currentTimeMillis() < end) {
String[] data_az = new String[];
int x=0;
data_az[x]= onDataEvent.getData()[0].getAcceleration()[0]);
x=x+1;
}
I can't seem to find the correct way to do it. Thank you for your answers.

Libgdx : .Flip() inside a for loop

Am i implementing this correctly? I'm having issues with the direction my character is in, yet the state manager is working correctly. I'm unsure whether this is the problem. I have my player facing right automatically when constructed yet he faces left.
I have two arrays for both right and left animation inside my assets manager, The original images are facing right, i declare that array and then flip the same image on the left array. Does the left array override the right?
int idleRIndex = 1;
TextureRegion[] idleRight = new TextureRegion[3];
for (int i = 0; i < idleRight.length; i++)
{
idleRight[i] = rubenSprite.findRegion("iframe" + idleRIndex);
idleRIndex++;
}
rubenIdleRight = new Animation(0.2f, idleRight);
int idleLIndex = 1;
TextureRegion[] idleLeft = new TextureRegion[3];
for (int i = 0; i < idleLeft.length; i++)
{
idleLeft[i] = rubenSprite.findRegion("iframe" + idleLIndex);
idleLeft[i].flip(true, false);
idleLIndex++;
}
rubenIdleLeft = new Animation(0.2f, idleLeft);
It seems so after a test. The findRegion("iframe" + idleLIndex) and for the right are returning the same object reference. So I think the flip for the left will also affect the right. Maybe you can create a new TextureRegion object from the atlas. It shouldn't be much overhead. Try:
idleLeft[i] = new TextureRegion(rubenSprite.findRegion("iframe" + idleLIndex));
Then the flip shouldn't affect the right anymore.

UnfoldingMaps add MarkerList after initialization

I'm writing an application where I show markers on a map using the library Unfolding Maps.
The application lets the user choose a year and depending on that value other markers are shown. This works perfect, but when the user selects another year I can't seem to get the other markers shown.
I've tried to completely renew the map but after that first time it doesn't redraw a map.
Besides that I've tried to add a MarkerManager to the map but then I get errors of OpenGL.
setup function:
public void setup() {
/*
* Provincies, set zoom to 10
*/
size(1000, 800, OPENGL);
this.map = new UnfoldingMap(this, new Microsoft.RoadProvider());
map.zoomAndPanTo(belgie, 8);
map.setPanningRestriction(belgie, 1);
map.setZoomRange(8, 8);
drawOtherMarker();
//map.getMarkerManager(markerRemarck.get(keyM)).enableDrawing();
MapUtils.createDefaultEventDispatcher(this, map);
}
function that creates the MarkerManager and adds it to the map
private void createMarkers(ArrayList<double[]> dataMarker) {
float size = 0;
int i = 0;
ListIterator<double[]> dataIt = dataMarker.listIterator();
ArrayList<SimplePointMarker> markList = new ArrayList<SimplePointMarker>();
while (dataIt.hasNext()) {
double[] element = dataIt.next();
SimplePointMarker point = new SimplePointMarker(new Location(
element[0], element[1]));
if (element[2] > 1000)
size = 120;
else if (element[2] > 100)
size = 60;
else if (element[2] > 10)
size = 30;
else
size = 20;
point.setRadius(size);
point.setColor(color(64,64,64,100));
point.setStrokeColor(color(178,34,34));
point.setStrokeWeight(30);
point.setStrokeWeight(0);
point.setId(Integer.toString(i++));
markList.add(point);
}
MarkerManager man = new MarkerManager(markList);
map.addMarkerManager(man);
}
When the map is drawn and another set of markers must be drawn the following function is called:
public void drawOtherMarker(){
if(!markerRemarck.containsKey(keyM)){
markerRemarck.put(keyM, totalMark++);
createMarkers(dataMarkerProvince);
}
if(dataMarkerTown != null){
markerRemarck.put(keyM + "city", totalMark++);
createMarkers(dataMarkerTown);
}
for(int i = 0; i < totalMark;++i)
map.getMarkerManager(i).disableDrawing();
map.getMarkerManager(markerRemarck.get(keyM)).enableDrawing();
}
another function brings in the data required to make the markers. I just don't seem to manage to add a MarkerManager after the first draw.
EDIT
This map is placed inside a JPanel. And the years are choosen with the help of a JComboBox. Once a year is chosen the "dataMarker" variable containing the information for creating markers is updated
thanks in advance for helping me out.

Barcode location while scanning

I'm using for my app the RedLaser library for barcode scanning (which is built off Zxing, I believe). Everything is working fine, while in scanning mode, any barcode that comes within view is scanned, but I don't want that, I want only barcodes that are aligned in a scanning area to be considered and the rest to be ignored.
The redlaser sample app, after which I implemented the library in my own app, had a rectangle on the layout of the scanning activiy, however that was ignored, as barcodes from any part of the screen were scanned and taken into account by the sample app.
Bottom line: I want my scanning activity to compare the location of the currently detected barcode and see if it is within the bounds of the "scanning area", if it is not then it won't be read.
Here is the code for the adjustment of the "scanning area":
viewfinderView = findViewById(R.id.view_finder);
LayoutParams params = new LayoutParams((int)(mDisplay.getWidth() * .75f),
(int)(mDisplay.getHeight() * .33f));
params.gravity = Gravity.CENTER;
viewfinderView.setLayoutParams(params);
The following code doesn't do anything, I just wrote it to exemplify the how everything works (since I don't have the source files for the Redlaser library), like the barcodelocation.
Set<BarcodeResult> allResults = (Set<BarcodeResult>) scanStatus.get(Status.STATUS_FOUND_BARCODES);
for( BarcodeResult s : allResults)
{
ArrayList<PointF> barcodelocation = s.barcodeLocation;
float x = barcodelocation.get(0).x;
float y = barcodelocation.get(0).y;
//there will be 4 points to each scanned barcode => 8 float's/barcode
}
Sorry for the long post, but I've been on this issue for a while now and I'm really stuck.
Any help is appreciated!
Managed to find a solution on the Redlaser site: turning the view into a rect then comparing the barcode location with that using .contain :
Rect scanningArea = new Rect(viewfinderView.getLeft(), viewfinderView.getTop(), viewfinderView.getRight(), viewfinderView.getBottom());
if(latestResult.iterator().hasNext())
{
boolean isInside = true;
ArrayList<PointF> barcodelocation = latestResult.iterator().next().barcodeLocation;
for (int i = 0; i < barcodelocation.size(); i++)
{
int x = (int) barcodelocation.get(i).x;
int y = (int) barcodelocation.get(i).y;
if (!scanningArea.contains(x, y))
{
isInside = false;
}
}
if (isInside)
{
//do stuff here
}
}
I'm still working on a few issues, but this question is answered now. Gonna go ahead and give myself a pat on the back. :)

Categories

Resources