I’m using the MPAndroidChart for my project and I have the problem with that.
It’s look like, every time, when I set new data on BarChart View, even if i use clear() method, some of the reason, created left padding. plz, how can i fixed that?
We also have the same problems. Obviously, method clear() dosen’t zero array of values YAxis. Also, method computeAxisValues(float min, float max) dosen’t check when length old array of values the YAxis is bigger then count of new values.
In your case, when you switch from Chart3 to Chart1, in first:
yAxis.mEntries = [0, 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000, 18000]
In second case:
yAxis.mEntries = [0, 30, 60, 90, 120, 150, 180, 210, 240, 18000]
That’s why BarChart View need padding from left, for bigger values, than actually need.
You can use that hack, for checking your case:
YAxis yAxis = barChart.getAxisLeft();
if (yAxis.mEntries.length > yAxis.mEntryCount){
float[] arr = yAxis.mEntries;
yAxis.mEntries = new float[yAxis.mEntryCount];
System.arraycopy(arr, 0, yAxis.mEntries, 0, yAxis.mEntryCount);
}
Related
At the moment I’m using DashPathEffect with hardcoded intervals to draw a circle as next:
float[] intervals = new float[]{ 3, 18 };
DashPathEffect path = new DashPathEffect(intervals, 0);
paint.setPathEffect(path);
… … … …
canvas.drawCircle(x, y, radius, paint);
But this produces a non-equidistant dash where the circle starts and ends, as shown in the image below:
I can of course adjust it manually, but this would only work for one specific device density, and produce again the same problem in a different display density.
What would the formula to calculate equidistant dashes?
You need n dashes plus n gaps to have the same total length as the circumference of the circle. The below code assumes you've correctly determined both the center point and the radius you want to use.
double circumference = 2 * Math.PI * radius;
float dashPlusGapSize = (float) (circumference / NUM_DASHES);
intervals[0] = dashPlusGapSize * DASH_PORTION;
intervals[1] = dashPlusGapSize * GAP_PORTION;
DashPathEffect effect = new DashPathEffect(intervals, 0);
paint.setPathEffect(effect);
canvas.drawCircle(center, center, radius, paint);
For instance, I've used NUM_DASHES = 20, DASH_PORTION = 0.75f, and GAP_PORTION = 0.25f, and I see:
You can use different values for these constants to change how many dashes you chop the cirlce into, or how big the dash/gap are relative to each other (as long as DASH_PORTION + GAP_PORTION adds up to 1).
In case you have a different figure you can use this method to measure your custom path length:
val measure = PathMeasure(path, false)
val length = measure.getLength()
The goal is to draw a circle having arcs that representing time slices. I have done this:
The problem is that there is a white space between each arch and I want to remove it. Also, the arcs are not aligned. This is my code:
int x = getWidth()/2;
int y = getHeight()/2;
int stroke = 20;
int radiusExternal = 250;
final RectF rect2 = new RectF();
rect2.set(x - radiusExternal, y - radiusExternal, x + radiusExternal, y + radiusExternal);
for (int i = 0; i < modProgram.getListEvents().size(); i++) {
ModEvent event = modProgram.getListEvents().get(i);
Paint paint2 = new Paint();
paint2.setColor(getColorEvent(event));
paint2.setStrokeWidth(stroke);
paint2.setAntiAlias(true);
paint2.setStrokeCap(Paint.Cap.BUTT);
paint2.setStyle(Paint.Style.STROKE);
int initialAngle = getInitialAngle(modProgram, event.getStartEvent());
int sweepAngle = getSweepAngle(modProgram, event, initialAngle);
canvas.drawArc(rect2, initialAngle, sweepAngle, false, paint2);
}
This is probably only a partial answer to deal with the gap between the arc-segments.
Here's a fiddle with javascript: http://jsfiddle.net/oakvLadb/
I've just randomly generated some start- and stop-angles.
The important part lies in the drawing of the arc:
ctx.arc(c.width/2,c.height/2,radius,startAngle,stopAngle+anglePadding);
The anglePadding is there to make sure that a little extra is drawn. When the next segment starts off being drawn from the previous segment's stopAngle, there will be a slit overlapp, making sure no gap is visible.
Next for the poor fit of the arc-segments
When it comes to the fact that it seems like the segments aren't meeting up correctly, the only thing I can think of is that the segments that you're drawing are not those of a perfect circle but an oval, and that's why they're not meeting up correctly. If your rect2 variable doesn't hold data for a perfect square, your segments won't match.
It looks like you do have a perfect square so they should align. Somewhere, there's a rounding error of some kind...
Instead of drawing each Arc next to each other, you can draw larger arcs like layer drawing.
Sorry for my english.
I solve this problem by setting LayerType to LAYER_TYPE_SOFTWARE. like below.
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
export const data = {
labels: ['a', 'b', 'c', 'd'],
datasets: [
{
label: 'Label',
data: [1298, 1798, 2500, 2200],
backgroundColor: [
'#687EEB',
'#FF4B5F',
'#AA71F2',
'#F29741',
],
borderColor: [
'#687EEB',
'#FF4B5F',
'#AA71F2',
'#F29741',
],
borderRadius: [
10,
10,
10,
10,
],
spacing: 20, // i think, this is what you need
borderWidth: 0,
cutout: '80%',
borderAlign: "inner"
},
],
};
I have searching a lot on Internet but I have not found a solution to my problem.
The issue is the following: I'm trying to make a Combined chart, in which there is a LineChart and a BarChart.
When I have, for example, these values, it works fine:
double[] valuesXaxisGraph1 = new double[]{1,2,3,4,5};
double[] dataGraph1 = new double[]{5,5,5,5,5};
double[] valuesXaxisGraph2 = new double[]{1,2,3,4,5}
double[] dataGraph2 = new double[]{6,6,6,6,6};
The graph created is the following:
However, if I use these values:
double[] valuesXaxisGraph1 = new double[]{1,2,3,4,5,6,7,8,9,10};
double[] dataGraph1 = new double[]{5,5,5,5,5,5,5,5,5,5};
double[] valuesXaxisGraph2 = new double[]{1,2,3,4,5};
double[] dataGraph2 = new double[]{6,6,6,6,6};
The graph shown is the following:
As you can see, the bars appears from 1 to 10, instead from 1 to 5. Because of that, these bars aren't positioned where they should be (1, 2, 3, 4...).
Why is happening this? What should I do to fix it?
Thanks in advance.
You can set the range for the second scale to be the same for the first scale. For instance, for setting the X axis maximum value, you would do:
renderer.setXAxisMax(renderer.getXAxisMax(0), 1);
I'm trying to get image pixels and save it in an array of int but when i check the array values sometimes fill it with 0's and other times with strange values (all the array have same value).
iv = (ImageView) findViewById (R.id.uploadImage);
iv.buildDrawingCache();
bmap = iv.getDrawingCache();
bmap.getPixels(pix, 0, width, 0, 0, width, hieght);
StringBuilder builder = new StringBuilder();
for(int i :pix) {
builder.append(" " + i + " ");
}
Toast.makeText(this, builder, Toast.LENGTH_LONG).show();
Try this:
int[] pixels = new int[yourBitmap.getHeight() * yourBitmap.getWidth()];
yourBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, yourBitmap.getWidth(), yourBitmap.getHeight());
I see a few possible problems here:
setDrawingCacheEnabled() isn't called
For this, you simply need to call setDrawingCacheEnabled(true) before using the cache. Make sure you set it back to false when you're done, or your ImageView won't render(at least on non-hardware accelerated devices)
width and height may not be right
I don't kow where you're getting your values for these, but you should use getWidth() and getHeight() for it. If you want to set it to a different value, that's fine, but then you need to create a scaled bitmap from the original one. Otherwise, there's no guarantee that the bitmap you get is the same size you think it is.
pix may be the wrong size
Hand in hand with the last point. Once you have accurate values for height and width, you need to make sure the array is the right size. pix = new int[height * width] is fine for this.
The third parameter should not be width.
Third parameter is called stride: The number of entries in pixels[] to skip between rows (must be >= bitmap's width).
Try
bmap.getPixels(pix, 0, width-1, 0, 0, width, hieght);
Everyone,
Can anyone help me to know is there anyway to create AnimateSprite Sheet from AndEngine as in COCOS2D.
Thanks.
Here you go! I believe this is what you are looking for.
AnimatedSprite runner = new AnimatedSprite(0, 0, mRunner);
// Animate with 100 milliseconds each frame, start at frame 0 and go through
// frame 3, set to true for looping otherwise false for no looping.
runner.animate(new long[] { 100, 100, 100, 100 }, 0, 3, true);
scene.attachChild(runner);
and in onLoadResources()
this.mRunnerTexture = new Texture(512, 128, TextureOptions.DEFAULT);
this.mRunner = TextureRegionFactory.createTiledFromAsset(this.mRunnerTexture, this, "gfx/runner.png", 0, 0, 4, 1); // 4 columns and 1 row, a 4x1 animated sprite
this.mEngine.getTextureManager().loadTextures(this.mRunnerTexture);