When my chart gets a lot of data the point labels overlap each other and as a result I want to give the user an option to turn them off by clicking a button but I can't find anything in the documentation on how to do this. Below is how I setup the point labels when the chart is created.
BarFormatter series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);'
PointLabelFormatter plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
series1Format.setPointLabelFormatter(plf);
Have you tried setting PointLabelFormatter to null inside your BarFormatter instance?
series1format.setPointLabelFormatter(null);
Then to turn the labels back on just add it back with your original method:
series1Format.setPointLabelFormatter(plf);
Now sure if this is the best way to turn on/off the point labels but if works :)
private void TogglePointLabelVisibility(boolean ShowLabels)
{
BarFormatter series1Format = new BarFormatter();
if(ShowLabels)
{
series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);
PointLabelFormatter plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
series1Format.setPointLabelFormatter(plf);
}
else
{
series1Format.setPointLabelFormatter(null);
}
SeriesAndFormatterList<XYSeries, XYSeriesFormatter> renderer = plot.getSeriesAndFormatterListForRenderer(BarRenderer.class);
renderer.setFormatter(series1, series1Format);
}
Related
I have made pie charts using mp-android chart.I have placed 9 charts in a grid but there is extra spaces between them.I need to remove those necessary spaces and make the edges touch each other.
This is the java method which inflates each piechart,I have tried the previous answers but nothing works.
static void makePie(PieChart pieChart, int type, boolean spin, Context con){
pieChart.setExtraOffsets(-30, -30, -30, -30);
ArrayList<PieEntry> yvalues = new ArrayList<>();
for(int i=0;i<type;i++){
yvalues.add(new PieEntry(10F, ""));
}
PieDataSet dataSet = new PieDataSet(yvalues, "Net Worth");
ArrayList<String> xVals = new ArrayList<String>();
PieData data = new PieData(dataSet);
pieChart.setCenterTextColor(Color.BLACK);
pieChart.setData(data);
pieChart.setDrawHoleEnabled(false);
final int[] MY_COLORS = {
Color.rgb(246,230,196),
Color.rgb(200,237,253),
Color.rgb(252,199,202),
Color.rgb(179,233,216),
Color.rgb(247,233,174),
Color.rgb(211,211,246),
Color.rgb(108,59,57),
Color.rgb(75,132,138),
Color.rgb(124,96,66),
Color.rgb(247,173,89),
Color.rgb(235,108,63),
Color.rgb(208,75,52),
Color.rgb(255,202,39),
Color.rgb(147,37,166),
Color.rgb(22,158,250),
Color.rgb(118,7,47),
Color.rgb(44,183,80),
Color.rgb(100,22,151),
Color.rgb(88,42,71),
Color.rgb(27,40,121),
Color.rgb(29,112,74),
Color.rgb(252,216,82),
Color.rgb(247,99,64),
Color.rgb(232,57,52)
};
ArrayList<Integer> colors = new ArrayList<Integer>();
dataSet.setColors(colors);
for(int i=0;i<type;i++){
colors.add(getRandom(MY_COLORS));
}
List<LegendEntry> entries = new ArrayList<>();
dataSet.setDrawValues(false);
data.setValueTextSize(16f);
data.setValueTextColor(Color.DKGRAY);
pieChart.getDescription().setEnabled(false);
pieChart.setTransparentCircleAlpha(0);
pieChart.getLegend().setEnabled(false);
pieChart.setRotationEnabled(false);
pieChart.setClickable(false);
pieChart.setTouchEnabled(false);
pieChart.setExtraOffsets(-10,0,-10,0);
pieChart.invalidate();
if(spin){
Animation animation = AnimationUtils.loadAnimation(con, R.anim.rotate);
pieChart.startAnimation(animation);
}
}
https://drive.google.com/open?id=1mIPMjFW3BlWhWLfQWIV65sfx9FO091pv
This is the output, there are spaces between the grids, which is taking too much space, andneeded to be removed so that the piecharts touch each other,
I've tried my self then I changed the setExtraOffsets in your code
it had an effect on the padding of your view but the shape was not circled any more
I recommend to remove setExtraOffsets in your code and see the result.
mention that you are using setExtraOffsets two parts of your code
I'm developing an app for android but I'm stuck at creating listeners for my buttons. I've already read tons of articles and did testing for several hours now but it just won't work. I did like in this example: https://gist.github.com/mattdesl/5461944 and I even have no errors in my code but my button shows no reaction at all.
Here is how I tried (or at least one of several tries):
...public MainMenuScreen(final Stapler gam) {
game = gam;
stage = new Stage();
table = new Table();
table.setFillParent(true);
stage.addActor(table);
Gdx.input.setInputProcessor(stage);
font = new BitmapFont(Gdx.files.internal("fonts/Blox.fnt"));
bodoque = new BitmapFont(Gdx.files.internal("fonts/bodoque.fnt"));
shapeRenderer = new ShapeRenderer();
// Add widgets to the table here.
TextureRegion upRegion = new TextureRegion(new Texture(
Gdx.files.internal("boxLila.png")));
TextureRegion downRegion = new TextureRegion(new Texture(
Gdx.files.internal("boxGruen.png")));
BitmapFont buttonFont = new BitmapFont(
Gdx.files.internal("fonts/Blox.fnt"), false);
TextButtonStyle style = new TextButtonStyle();
style.up = new TextureRegionDrawable(upRegion);
style.down = new TextureRegionDrawable(downRegion);
style.font = buttonFont;
play = new TextButton("Play", style);
table.add(play);
play.addListener(new ClickListener() {
public void clicked(InputEvent e, float x, float y) {
game.setScreen(game.gameScreen);
Gdx.app.log("Click", "performed"); // -> never happend
}
});
// add the button with a fixed width
table.add(play).width(500);
// then move down a row
table.row();
}
...
I solved or at least found out why its not working. I created an instance of my gamworld with an own InputProcessor and when I don't create that, the listener works.. but now I have to figure out how to use both..
You can add a ChangeListener for this. Something like:
play.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
game.setScreen(game.gameScreen);
}
});
This is the way to listen to button clicks like it is explained in the libgdx scene2 wiki.
I am using achartengine to display charts in an Android app.
The app allows the user to display different datasets and different charts types depending on the selections they make from spinners.
My problem is this. The original chart displays correctly and all zoom, pan, and onClick events preform as expected. But when I remove the first chart and add another, the charts will not zoom or pan from touch and onClick will not return selected point data. The achartengine zoom and reset buttons still display and work as expected. To remove a chart and add another I have used different variations of the following code with the same results.
private void repaint() {
mchart1_LL_pie = (LinearLayout) this.findViewById(R.id.chart1_LL_pie);
if (mChart1_ChartView_pie != null) {
mchart1_LL_pie.removeView(mChart1_ChartView_pie);
}
mChart1_ChartView_pie = ChartFactory.getPieChartView(getApplicationContext(), mChart1_Pie_Series, mChart1_Pie_Renderer);
mchart1_LL_pie.addView(mChart1_ChartView_pie, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
I have also tried to remove all the renderers and clear the data series with the following code.
mChart1_Pie_Renderer.removeAllRenderers();
int size = mChart1_Pie_Series.getItemCount();
for (int i = 0; i < size; i++) {
mChart1_Pie_Series.remove(0);
And then display the chart with a rebuilt dataset and renderer using the following.
mChart1_ChartView_pie = ChartFactory.getPieChartView(getApplicationContext(), mChart1_Pie_Series, mChart1_Pie_Renderer);
The problem with this approach is that the next chart is not displayed until the display is touched. After the display is touched, the correct chart is displayed and all zoom, pan and onClick events work properly.
Has anyone experienced this problem? If so, how did you solve it?
Any help or suggestions would be greatly appreciated. Thank you
Don
I am doing an application with charts. I have an evolution chart with TimeSeries. I paste my function to draw the chart. It can help you :)
public void drawChart() {
mChartView = null;
mDataset = null;
mRenderer = null;
mDataset = new XYMultipleSeriesDataset();
mRenderer = new XYMultipleSeriesRenderer();
mRenderer.setAxisTitleTextSize(15);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.BLUE);
r.setFillPoints(true);
mRenderer.addSeriesRenderer(r);
mRenderer.setZoomEnabled(true);
mRenderer.setShowGrid(true);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setAxesColor(Color.BLACK);
mRenderer.setShowLegend(true);
mRenderer.setShowLabels(true);
mRenderer.setLabelsColor(Color.BLACK);
mRenderer.setBackgroundColor(Color.TRANSPARENT);
mRenderer.setYLabelsPadding(20);
mRenderer.setXLabelsPadding(7);
mRenderer.setYLabelsAlign(Align.LEFT);
mRenderer.setMarginsColor(Color.rgb(220, 220, 220));
mRenderer.setAxesColor(Color.BLACK);
mRenderer.setLabelsColor(Color.BLACK);
mRenderer.setXLabelsColor(Color.BLACK);
mRenderer.setYLabelsColor(0, Color.BLACK);
// mRenderer.setAxisTitleTextSize(30);
mRenderer.setGridColor(Color.BLACK);
mRenderer.setXRoundedLabels(false);
// mRenderer.setLabelsTextSize(25);
mRenderer.setYTitle(Config.getResource("PRICE") + "("
+ dto.getCurrencyCode() + ")");
mRenderer.setMargins(new int[] { 0, 60, 50, 0 });
mRenderer.setMarginsColor(Color.WHITE);
// mRenderer.setXTitle("Date");
mRenderer.setShowLegend(false);
mRenderer.setInScroll(true);
evolutionSecurity = new TimeSeries("");
mDataset.addSeries(evolutionSecurity);
fillDataEvolution(); //Get data into serie
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"dd-MM-yy");
LinearLayout layout = (LinearLayout) findViewById(R.id.graphe_evolution_rate_currency);
layout.addView(mChartView);
if (layout != null)
layout.removeAllViews();
layout.addView(mChartView);
mChartView.repaint();
mChartView = null;
}
Then when i select an another value in my spinner i call this method and the chart is redrawn correctly.
I'm creating a line chart with multiple series using aChartEngine library.
I have modified the code in XYChartBuilder.java to create a sample and test if i can fill the area under each series with a specific color. I have an issue when trying to fill with a different color the area below each series. At the areas where the series overlap, the lines of the underlying series are not shown.
Following is the code i have used to add the series and data on the graph
public void addSeries(int id) {
String seriesTitle = "Series " + (mDataset.getSeriesCount() + 1);
// create a new series of data
XYSeries series = new XYSeries(seriesTitle);
mDataset.addSeries(series);
mCurrentSeries = series;
// create a new renderer for the new series
XYSeriesRenderer renderer = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
// set some renderer properties
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
renderer.setDisplayChartValues(true);
renderer.setDisplayChartValuesDistance(10);
renderer.setLineWidth(2);
if (id == 1) {
FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BELOW);
fill.setColor(Color.BLUE);
renderer.addFillOutsideLine(fill);
renderer.setColor(Color.BLUE);
renderer.setPointStyle(PointStyle.SQUARE);
}
if (id == 2) {
FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BELOW);
fill.setColor(Color.WHITE);
renderer.addFillOutsideLine(fill);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setColor(Color.GREEN);
}
if (id == 3) {
FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BELOW);
fill.setColor(Color.YELLOW);
renderer.addFillOutsideLine(fill);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setColor(Color.YELLOW);
}
mCurrentRenderer = renderer;
mChartView.repaint();
}
public void addData(double x, double y) {
// add a new data point to the current series
mCurrentSeries.add(x, y);
// repaint the chart such as the newly added point to be visible
mChartView.repaint();
}
When I need to create the series i call
addSeries(1);
addData(0, 0);
addData(2, 3);
addData(4, 0);
addSeries(2);
addData(2, 0);
addData(6, 3);
addData(8, 0);
addSeries(3);
addData(6, 0);
addData(9, 3);
addData(11, 0);
In the case where I specify in the addSeries function the FillOutsideLine object but do not set the color I get the expected behavior I want. However,the areas under each series are drawn with the same color (blue - it seems to be the default).
Unfortunately I'm new and my reputation is still low, thus I cannot upload any images.
Any help is much appreciated.
Thanks,
Lupe.
I found the solution to my problem so I'm listing it in case someone else is having the same issue. The problem occurred as I used a solid color to paint the area under the series. I tested it with a semi-transparent color and the problem is now solved.
Example:
fill.setColor(Color.parseColor("#5500FF66"));
L.
First i give my View show below. and give some explanation:
In my ViewGroup i have two GraphicalView, each of them share the same size space. Let's just call the chart above chartA and below one chartB.
Then i have some questions:
If i make a move a movement on chartA ,how could i make the chartB move just as my finger moving on chartB?
If i pinch on chartA can also chartB change auto?
I want to add some callback function to some points? Does ACE supports this?
I do not want to show numbers negative while user pinching.How can I make this point?
Last is my chart code:
mDataset.addSeries(series);
PointStyle style = PointStyle.CIRCLE;
renderer = buildRenderer(lineColor, style, true);
setChartSettings(renderer, "X", "Y", 0, 50, yMin, yMax, Color.WHITE,
Color.WHITE, title,chartColor);
GraphicalView chart = ChartFactory.getLineChartView(context, mDataset, renderer);
layout.addView(chart, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
HashMap map = new HashMap();
and the renderer:
protected XYMultipleSeriesRenderer buildRenderer(int color,
PointStyle style,
boolean fill) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(color);
r.setPointStyle(style);
r.setFillPoints(fill);
r.setLineWidth(3);
renderer.addSeriesRenderer(r);
return renderer;
}
I random all the data i want.
You have to register a PanListener on your chartA and on every panApplied event, just do: rendererB.setXAxisMin(rendererA.getXAxisMin()); and the same for max X and for the Y axis and then call chartB.repaint();
Same as the above, just that you need to add a ZoomListener.
You can set a click listener: chartA.setOnClickListener();
Please reformulate into a separate question.
Also, see this code showing you how to use the above APIs.