I am using achartengine, to plot a line graph. I am trying to customize it to have Y axis lines which pass through the values, and show the values on top. Does any one have any idea, how can I achieve an effect like this one :
Here is what I currently have :
And here is the code Snippet :
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
renderer.setColor(Color.WHITE);
renderer.setLineWidth(2f);
XYMultipleSeriesRenderer seriesRenderer = new XYMultipleSeriesRenderer();
seriesRenderer.addSeriesRenderer(renderer);
seriesRenderer.setLabelsTextSize(20); // Text size
seriesRenderer.setShowAxes(true); // show both axes
seriesRenderer.setShowLegend(false);
seriesRenderer.setShowGridX(true); // X grid helps identify values
seriesRenderer.setShowLabels(true); // See the values
seriesRenderer.setYLabelsAlign(Align.RIGHT);
seriesRenderer.setZoomButtonsVisible(false); // bye bye zoom
seriesRenderer.setXAxisMin(0);
seriesRenderer.setXAxisMax(10);
seriesRenderer.setTextTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Lifestyle Rounded M54.ttf"));
seriesRenderer.setPointSize(10f);
seriesRenderer.setPanEnabled(true, false);
View view = ChartFactory.getLineChartView(context, dataset, seriesRenderer);
return view;
Any input will be highly appreciated.
You can add annotation that can be displayed wherever you need on the graph:
series.addAnnotation(text, x, y);
Related
hello guys i'm trying to write a simple line graph but it does not render the last value on the lines. I want to show all the values on the linegraph.
http://imgur.com/EHFh1xP
http://imgur.com/CWl8CDi
the code is tried is
XYSeriesRenderer rendererLijn0 = new XYSeriesRenderer();
rendererLijn0.setColor(Color.RED);
rendererLijn0.setChartValuesTextSize(rendererLijn0.getChartValuesTextSize()+20);
rendererLijn0.setDisplayChartValues(true);
rendererLijn0.setPointStyle(PointStyle.CIRCLE);
rendererLijn0.setFillPoints(true);
rendererLijn0.setDisplayBoundingPoints(true);
XYSeriesRenderer rendererLijn1 = new XYSeriesRenderer();
rendererLijn1.setDisplayChartValues(true);
rendererLijn1.setPointStyle(PointStyle.CIRCLE);
rendererLijn1.setFillPoints(true);
rendererLijn1.setDisplayBoundingPoints(true);
AlleSeries.addSeries(GrafiekDataLijn0);
AlleSeries.addSeries(GrafiekDataLijn1);
AlleRenderers.addSeriesRenderer(rendererLijn0);
AlleRenderers.addSeriesRenderer(rendererLijn1);
AlleRenderers.setXTitle("Tijden");
AlleRenderers.setYTitle("Waarde Lijnen");
AlleRenderers.setYAxisMin(0);
AlleRenderers.setYAxisMax((hoogste + 20));
AlleRenderers.setZoomEnabled(true);
AlleRenderers.setZoomButtonsVisible(true);
AlleRenderers.setXLabelsAlign(Align.CENTER);
AlleRenderers.setXAxisMin(0-0.2);
AlleRenderers.setXAxisMax(GrafiekDataLijn1.getItemCount());
GraphicalView Grafiek = ChartFactory.getLineChartView(
getBaseContext(), AlleSeries, AlleRenderers);
lnGrafiek.addView(Grafiek);
Try giving some padding to your view:
Grafiek.setPadding(0,0,20,0);//(left, top, right, bottom);
am trying to draw a line chart with achartengine in an Android App. The graph auto-refreshes every few seconds. The problem is : the axes become invisible if there is no data to plot. How do I make the axes appear even if there is nothing to plot?
Kindly help.
private XYMultipleSeriesDataset graphDataset = null;
private XYMultipleSeriesRenderer graphRenderer = null;
private GraphicalView graphView;
.....
.....
this.graphDataset = new XYMultipleSeriesDataset();
this.graphRenderer = new XYMultipleSeriesRenderer();
this.graphRenderer.setXLabels(0);
...
/// other initialization code, like labels & fonts
...
// then i add the data to the series
XYSeries series = new XYSeries("Simple graph");
for (int i=0; i<valueArray.size();i++) {
series.add(valueArray.get(i), yValue.get(i));
}
this.graphDataset.addSeries(series);
....
// then I do renderer initialization
XYSeriesRenderer xyRenderer = this.setChartLineProperties(index);
...
// then finally initializing the graphview
this.graphView = ChartFactory.getLineChartView(this, this.graphDataset,
this.graphRenderer);
In order for the axes to be displayed, the chart needs to know what values range it has to display. If there is no value added to the dataset, the range can be set this way:
renderer.setXAxisMin(minX);
renderer.setXAxisMax(maxX);
renderer.setYAxisMin(minY);
renderer.setYAxisMax(maxY);
I am trying to develop an app that will display a graph.On the y-axis there will be data and on the x-axis months(e.g jan,feb,march,april ...).As far as i know am trying to use annotations to add the months but am having errors.I cant seem to find a good enough example on how to use annotations.Please help.Heres is my code.
public class LineGraph {
public Intent getIntent(Context context){
int x[]={1,2,3,4,5,6};
int y[]={1,4,9,16,25,36};
String xaxis[]={"jan","feb","march","april","june","july","august"};
TimeSeries series=new TimeSeries("line1");
for(int i=0;i<x.length;i++){
series.add(x[i],y[i]);
series.addAnnotation(xaxis[i], x[i], y[i]);
}
XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer renderer=new XYSeriesRenderer();
renderer.setColor(Color.BLUE);
renderer.setPointStyle(PointStyle.SQUARE);
renderer.setFillPoints(true);
XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
mRenderer.setChartTitle("haha");
Intent intent = ChartFactory.getLineChartIntent(context,dataset,mRenderer,"Line graph title");
return intent;
}
}
I am trying to display text lables for the x-axis instead of integer values.A better aproach is also welcome.
Annotations are a good choice for displaying random text wherever you need on the graph. In order to display custom labels, you will have to add custom labels:
renderer.addXTextLabel(x, text);
You will also need to disable the default numerical labels:
renderer.setXLabels(0);
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.
I want to create XY plot with positive and negative numbers on both axys. By default achartnegine shows negative values of series but the start popint is always zero^ graph start from zero and next nubmer is something like -50, -40 etc. I have tried to avoid this but haven;t succed yet. Could you please suggest the right approach?
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesXY);
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
//renderer.setXAxisMin(-10f);
//renderer.setYAxisMin(-250f);
//renderer.setBarSpacing(SPACING);
//renderer.setRange(new double[] { -250d, 250d});
XYSeriesRenderer sRenderer = new XYSeriesRenderer();
sRenderer.setColor(Color.BLUE);
sRenderer.setFillBelowLine(false);
sRenderer.setChartValuesSpacing(SPACING);
sRenderer.setFillBelowLineColor(Color.WHITE);
sRenderer.setFillPoints(false);
renderer.addSeriesRenderer(sRenderer);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.WHITE);
renderer.setMarginsColor(Color.WHITE);
renderer.setAxesColor(Color.BLACK);
renderer.setXLabelsColor(Color.BLUE);
renderer.setYLabelsColor(0, Color.BLUE);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
GraphicalView chartView = ChartFactory.getLineChartView(
getActivity(),
dataset, renderer);
plot.removeAllViews();
plot.addView(chartView, new LayoutParams(
LayoutParams.MATCH_PARENT, 200));
chartView.repaint();
I use LineChartView
The answer is that you cannot put the axis in the center of the chart with AChartEngine as it is out of the box.