I want to click each slices in the chart and then I have to show a popup based on clicking in each slices. I have implemented onclicklistener, but it is not working.
Code :
Clicking part:
gv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = gv.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
int seriesIndex = seriesSelection.getSeriesIndex();
String selectedSeries = "Income";
if (seriesIndex == 0)
selectedSeries = "Income";
else
selectedSeries = "Expense";
int amount = (int) seriesSelection.getValue();
Toast.makeText(
getActivity(),
selectedSeries + " in " + "" + " : " + amount,
Toast.LENGTH_SHORT).show();
}
}
});
Rendering part:
public GraphicalView createIntent(List<double[]> values1, int[] colors, List<String[]> titles) {
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setApplyBackgroundColor(false);
renderer.setShowLegend(false);
renderer.setShowLabels(false);
renderer.setStartAngle(chartStartAngle); // 0 is 90 degree
renderer.setLabelsColor(Color.BLACK);
//renderer.setBackgroundColor(ContextCompat.getColor(get));
renderer.setScale((float) 1.40);
renderer.setPanEnabled(false);
renderer.setZoomEnabled(false);
renderer.setClickEnabled(true);//
renderer.setSelectableBuffer(100);
return ChartFactory.getDoughnutChartView(getActivity().getApplicationContext(),
buildMultipleCategoryDataset("Project", titles, values1),
renderer);
}
Related
We are using AChart engine to draw bar graph. As per design requirement have to place an image on top of the tallest bar in the graph. We know the index of largest value in the XY series. Is there any method to find the coordinates of the tallest bar to position the image? Below is the helper class we are using to generate the bar graph. When user taps on the bar we have to place an image on top of the bar.
Issues :
Not able to get the click event correctly
How to position the image on top of the bar
public class BarGraphHelper {
private Context mContext;
private BarGraph mBarGraph;
private DisplayMetrics mMetrics;
private XYMultipleSeriesDataset mDataset;
private XYMultipleSeriesRenderer renderer;
private View barChartView = null;
private BarChart chart;
public BarGraphHelper(Context context, BarGraph barGraph){
mContext = context;
mBarGraph = barGraph;
init();
}
private void init() {
renderer = new XYMultipleSeriesRenderer();
mDataset = new XYMultipleSeriesDataset();
mMetrics = mContext.getResources().getDisplayMetrics();
}
public View getBarGraphView(){
if(renderer == null){
return null;
}
getBarGraphDataset();
renderer = getBarRenderer();
setBarGraphSettings();
chart = new BarChart(mDataset, renderer, Type.DEFAULT);
barChartView = new GraphicalView(mContext, chart);
barChartView.setOnClickListener(onBarClick);
return barChartView;
}
private void setBarGraphSettings() {
if(renderer != null){
renderer.setXAxisMin(0.5);
renderer.setYAxisMin(0);
renderer.setYAxisMax(110);
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0, Color.WHITE);
renderer.setXTitle("mins");
renderer.setYTitle("Tweets");
renderer.setShowAxes(true);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setBarSpacing(0.2);
renderer.setBarWidth(15);
renderer.setShowGrid(false);
renderer.setYLabels(0);
renderer.setXLabels(0); // sets the number of integer labels to appear
int margin[] = renderer.getMargins();
renderer.setMargins(new int[] { (int)convertDiptoPixel(margin[0]), (int)convertDiptoPixel(margin[1]), (int)convertDiptoPixel(margin[2]), (int)convertDiptoPixel(margin[3]) });
renderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
renderer.setLabelsColor(Color.WHITE);
renderer.setAxisTitleTextSize(convertDiptoPixel(renderer.getAxisTitleTextSize()));
renderer.setShowLegend(false);
renderer.setLabelsTextSize(convertDiptoPixel(renderer.getLabelsTextSize()));
renderer.setZoomButtonsVisible(false);
renderer.setPanEnabled(true, true);
renderer.setZoomEnabled(false, false);
renderer.setClickEnabled(true);
renderer.setSelectableBuffer(10);
}
}
private void getBarGraphDataset() {
if(mBarGraph != null){
CategorySeries positiveSeries = new CategorySeries("Positive");
ArrayList<Sentiment> sentimentList = mBarGraph.getSentimentList();
if(sentimentList != null && !sentimentList.isEmpty()){
Sentiment sentiment = null;
for(int i=0; i< sentimentList.size(); i++){
sentiment = sentimentList.get(i);
positiveSeries.add(sentiment.getTotalTweetCount());
}
mDataset.addSeries(positiveSeries.toXYSeries());
}
}
}
public XYMultipleSeriesRenderer getBarRenderer() {
XYSeriesRenderer seriesRenderer = new XYSeriesRenderer();
seriesRenderer.setColor(Color.parseColor("#5FB356"));
seriesRenderer.setDisplayChartValues(true);
renderer.addSeriesRenderer(seriesRenderer);
return renderer;
}
private float convertDiptoPixel(float pixel){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, pixel, mMetrics);
}
OnClickListener onBarClick = new OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = ((GraphicalView) barChartView).getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(mContext, "No chart element was clicked", Toast.LENGTH_SHORT)
.show();
} else {
double[] screenPoint = chart.toScreenPoint(new double[] {
seriesSelection.getXValue(),seriesSelection.getValue() },0);
Toast toast = Toast.makeText(
mContext,
"Chart element in series index " + seriesSelection.getSeriesIndex()
+ " data point index " + seriesSelection.getPointIndex() + " was clicked"
+ " closest point value X=" + seriesSelection.getXValue() + ", Y=" + seriesSelection.getValue()
+ " clicked point value X=" + (int)screenPoint[0] + ", Y=" + (int)screenPoint[1], Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, (int)screenPoint[0],(int)screenPoint[1]);
toast.show();
}
}
};
}
Hi i am using achartengine's pie-chart to represent my actual sales, now as my app starts one of the chart element in the piechart should get highlighted, like when we do the onclick on pie chart.
Below is the code for my piechart
final DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setPanEnabled(false);// Disable User Interaction
renderer.setLabelsColor(Color.BLACK);
renderer.setShowLegend(true);
renderer.setLegendTextSize(20);
renderer.setInScroll(true);
renderer.setStartAngle(180);
renderer.setChartTitle("Sales By Market Segment- Month");
renderer.setLabelsTextSize(22);
final CategorySeries categorySeries = new CategorySeries("Sales");
categorySeries.add("Craft1", cursor.getInt(1));
categorySeries.add("product1", cursor.getInt(2) );
categorySeries.add("product2", cursor.getInt(3) );
categorySeries.add("product", cursor.getInt(4));
categorySeries.add("product1", cursor.getInt(5));
mChartView2=ChartFactory.getPieChartView(context, categorySeries,renderer);
parent.addView(mChartView2);
renderer.setClickEnabled(true);
mChartView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView2.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(getActivity(), "No chart element selected", Toast.LENGTH_SHORT)
.show();
}else {
for (int i = 0; i < categorySeries.getItemCount(); i++) {
renderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
}
mChartView2.repaint();
Toast.makeText(
getActivity(),
"Chart data point index " + seriesSelection.getPointIndex() + " selected"
+ " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}
}
});
return ChartFactory.getPieChartIntent(context, categorySeries, renderer,null);
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
products are getting highlighted when clicking but I want to highlight one product, when app starts.
Found the solution:
mChartView2=ChartFactory.getPieChartView(context, categorySeries,renderer);
parent.addView(mChartView2);
renderer.getSeriesRendererAt(0).setHighlighted(true);
mChartView2.repaint();
I am creating Stacked bar chart using Achartengine library. The values doesn't show properly. I want want to show the chart value like this {20,20,20} at top of the bar and align to center.
Here is my code
dataset.addSeries(JumlahSeries);
dataset.addSeries(JumlahSeries1);
dataset.addSeries(FirstSeries);
final XYSeriesRenderer FirstRenderer = new XYSeriesRenderer();
Log.d("Error Here","29");
FirstRenderer.setColor(Color.BLUE);
FirstRenderer.setFillPoints(false);
FirstRenderer.setLineWidth(5);
FirstRenderer.setChartValuesTextSize(15);
FirstRenderer.setDisplayChartValues(false);
// Creating XYSeriesRenderer to customize expenseSeries
Log.d("Error Here","30");
final XYSeriesRenderer SecondRenderer = new XYSeriesRenderer();
SecondRenderer.setColor(Color.RED);
SecondRenderer.setFillPoints(false);
SecondRenderer.setLineWidth(5);
SecondRenderer.setDisplayChartValues(false);
SecondRenderer.setChartValuesTextSize(15);
Log.d("Error Here","31");
final XYSeriesRenderer ThirdRenderer = new XYSeriesRenderer();
ThirdRenderer.setFillPoints(false);
ThirdRenderer.setColor(Color.GREEN);
ThirdRenderer.setLineWidth(5);
ThirdRenderer.setDisplayChartValues(false);
ThirdRenderer.setChartValuesTextSize(15);
// Creating a XYMultipleSeriesRenderer to customize the whole chart
final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
//zoomIn = new Zoom((GraphicalView) mChart, true, multiRenderer.getZoomRate());
//multiRenderer.setChartTitle("\n"+"\n"+ title);
multiRenderer.setChartTitleTextSize(20);
//multiRenderer.setXTitle("\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"Laporan Pada :"+ DateToDisplay);
multiRenderer.setShowGridX(false);
multiRenderer.setShowLegend(true);
multiRenderer.setShowLabels(true);
multiRenderer.setAxisTitleTextSize(15);
multiRenderer.setMargins(new int[] { 70,70,25,25});
multiRenderer.setYTitle("Bilangan\n\n"+"\n"+"\n"+"\n");
multiRenderer.setZoomButtonsVisible(true);
multiRenderer.setBarSpacing(spacing);
multiRenderer.setYAxisMax(max);
multiRenderer.setYLabelsColor(0, Color.BLACK);
multiRenderer.setXLabelsColor(Color.BLACK);
multiRenderer.setXLabels(0);
multiRenderer.setPanEnabled(true, false);
double Xmax = 2;
if(StacktotalX.getTotal().size()<5){
Log.d("Error Here","32");
Xmax=StacktotalX.getTotal().size()*1.3;
}
multiRenderer.setXAxisMax(Xmax) ;
multiRenderer.setXAxisMin(-1) ;
multiRenderer.setLabelsTextSize(13);
multiRenderer.setZoomEnabled(true,false);
multiRenderer.setClickEnabled(true);
for (int i = 0; i < StacktotalX.getTotal().size(); i++)
{
Log.d("Error Here","33");
multiRenderer.addXTextLabel(i,StacktotalX.getTotal().get(i).toString());
Log.d("texl",StacktotalX.getTotal().get(i).toString());
}
multiRenderer.addSeriesRenderer(ThirdRenderer);
multiRenderer.addSeriesRenderer(SecondRenderer);
multiRenderer.addSeriesRenderer(FirstRenderer);
Log.d("Error Here","34");
mChart = ChartFactory.getBarChartView(getBaseContext(), dataset, multiRenderer, Pattern);
multiRenderer.setApplyBackgroundColor(true);
multiRenderer.setBackgroundColor(Color.TRANSPARENT);
multiRenderer.setMarginsColor(Color.TRANSPARENT);
multiRenderer.setLabelsColor(Color.BLACK);
mChart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
int seriesIndex = seriesSelection.getSeriesIndex();
String selectedSeries="Bilangan";
Log.d("seriesIndex",String.valueOf(seriesIndex));
// String yobject = [(int)seriesSelection.getXValue()-1];
// Getting the clicked Month
//String month = x[(int)seriesSelection.getXValue()-1];
// Getting the y value
int amount = (int) seriesSelection.getValue();
Log.d("amout",String.valueOf(amount));
Toast.makeText(
getBaseContext(),
selectedSeries + " in " + " : " + amount ,
Toast.LENGTH_SHORT).show();
}
}
});
// Start Activity*/
chartContainer.addView(mChart);
new Thread(new Runnable() {
public void run() {
long time = 0;
time = 9000/max;
Log.d("Error Here","35");
if(time>1.5){
time = (long) 1.5;
}if(time<0.5){
time = (long) 0.5;
}
int animation = 1;
Log.d("Error Here","36");
while(true){
boolean stop = true;
for(int k=0; k< StacktotalX.getTotal().size();k++){
// for(int k=0;k<jum1.size();k++)
// {
// JumlahSeries.add(k,jum1.get(tims));
// tims++;
// }
if(animation<= jum3.get(k)){
Log.d("Error Here","37");
FirstSeries.add(k,animation);
stop=false;
}
if(animation<= jum.get(k)){
Log.d("Error Here","38");
JumlahSeries1.add(k,animation);
stop=false;
}
if(animation<= jum1.get(k)){
Log.d("Error Here","39");
JumlahSeries.add(k,animation);
stop=false;
}
}
try {
Log.d("Error Here","40");
Thread.sleep(time);
Log.d("Error Here","4");
mChart.repaint();
}catch (InterruptedException e) {
e.printStackTrace();
}
animation++;
if(stop){
FirstSeries.clear();
JumlahSeries1.clear();
JumlahSeries.clear();
for(int y=0;y<StacktotalX.getTotal().size();y++)
{
FirstSeries.add(y,jum3.get(y));
JumlahSeries1.add(y, jum.get(y));
JumlahSeries.add(y, jum1.get(y));
}
FirstRenderer.setChartValuesSpacing(10);
FirstRenderer.setChartValuesTextAlign(Align.LEFT);
FirstRenderer.setDisplayChartValues(true);
FirstRenderer.getChartValuesTextAlign();
SecondRenderer.setChartValuesSpacing(10);
SecondRenderer.setChartValuesTextAlign(Align.CENTER);
SecondRenderer.setDisplayChartValues(true);
SecondRenderer.getChartValuesTextAlign();
ThirdRenderer.setChartValuesSpacing(10);
ThirdRenderer.setChartValuesTextAlign(Align.RIGHT);
ThirdRenderer.setDisplayChartValues(true);
ThirdRenderer.getChartValuesTextAlign();
mChart.repaint();
break;
}
}
}
}).start();*
This is my image that now is showing:-
In my android app, I need to change the Background color of each Item of my ListView seperately.
I found no examples or helpful documentation. The background should change if the value of a double is 0. I set the ListView Property: android:drawSelectorOnTop="true" and used following code:
(All of it functions, only the background doesn't change!) How can I solve this problem?
public void onClickButtonOKStand (View view) {
EditAusgabe = (EditText) findViewById(R.id.EditText01);
if (EditAusgabe.getText().toString().length() <= 0) {
Toast T = Toast.makeText(getApplicationContext(), "Eingabe ungültig! Geben Sie einen Betrag ein", Toast.LENGTH_LONG);
T.show();
return;
}
if (EditAusgabe.getText().toString() == ".") {
Toast T = Toast.makeText(getApplicationContext(), "Eingabe ungültig! Geben Sie einen Betrag ein", Toast.LENGTH_LONG);
T.show();
return;
}
Z = Double.parseDouble(EditAusgabe.getText().toString());
if (VArt == "Down") {
if (VStand >= Z) {
VStand = VStand - Z;
if (VStand <= 0.39) {
Toast T = Toast.makeText(getApplicationContext(), "Ihr Guthaben ist aufgebraucht!", Toast.LENGTH_strong textLONG);
T.show();
VStand = 0.00;
****************** The next line is my problem: ******************************
StartListe.getChildAt(Position).setBackgroundColor(color.holo_red_light);
}
}
else if (VStand < Z) {
Toast T = Toast.makeText(getApplicationContext(), "Vorgang nicht möglich! Ihr Konto liegt bei " + FORMAT.format(VStand) + " €.", Toast.LENGTH_LONG);
T.show();
EditAusgabe.setText("");
return;
}
}
if (VArt == "Up") {
VStand = VStand + Z;
}
Stand.set(Position, FORMAT.format(VStand));
Liste.set(Position, (VName + " " + FORMAT.format(VStand) + " € / " + FORMAT.format(VWert) + " €"));
ListeAktualisieren();
}
public void ListeAktualisieren () {
setContentView(R.layout.activity_ausgabenkontrolle);
ArrayAdapter<String> ListenAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Liste);
StartListe = (ListView) findViewById(R.id.listView1);
StartListe.setAdapter(ListenAdapter);
StartListe.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> ListenAdapter, View view, int i, long ID) {
// TODO Auto-generated method stub
Item = view;
Position = ListenAdapter.getPositionForView(view);
VName = Namen.get(Position);
VArt = Arten.get(Position);
VWert = Double.parseDouble(Werte.get(Position).toString());
VStand = Double.parseDouble(Stand.get(Position).toString());
setContentView(R.layout.activity_stand);
if (VArt == "Down") {
if (VStand == 0) {
Toast T = Toast.makeText(getApplicationContext(), "Ihr Guthaben ist aufgebraucht!", Toast.LENGTH_LONG);
T.show();
}
}
}
});
registerForContextMenu(StartListe);
}
I think the way to change the background color in response to a click is to apply the change to the incoming View given to you in your onClickListener implementation. You seem to be messing about with setContentViews, etc. which isn't the way to go. SetContentView sets your overall layout, and there's rarely a reason to call it more than once in an Activity.
i am drawing a bar chart and pie chart to represent the various application names in it using the achartengine library.
When i instantiate CategorySeries object it requires a series title as :
CategorySeries series = new CategorySeries("title") //IN BAR CHART
CategorySeries series = new CategorySeries("title") //IN PIE CHART
Unlike Pie chart the applications name does not get inflated at the bottom of the bar chart
say, in case of pie chart its as follows :
(1) application 1
(2) application 2
(3) application ... up to
(10) application 10.
But its not showing in case of bar char but instead its showing as :
(1) NUMBER OF APPLICATIONS ---->>> (This is the series title i had
passed in as the parameter while
instantiating the object of CategorySeries)
PLEASE SUGGEST ME TO SHOW THE KEY OF BAR CHART ASWELL,I HAVE ATTACHED A CODE SNIPPET BELOW
if (c.getCount() > 0) {
if (! mPieChart) {
series = new CategorySeries("NUMBER OF APPLICATIONS");
getActivity().startManagingCursor(c);
c.moveToPosition(-1);
//series.clear();
while (c.moveToNext()) {
recievedBytes = c.getLong(ApplicationDataCounterDao.CONTENT_RECEIVED_COLUMN);
sentBytes = c.getLong(ApplicationDataCounterDao.CONTENT_SENT_COLUMN);
totalBytes = (recievedBytes + sentBytes) / (1024 * 1024);
if (totalBytes > 0) {
applicationInfo
.add(new ApplicationDataUsage(
c.getString(ApplicationDataCounterDao.CONTENT_APPLICATION_NAME_COLUMN),
Double.toString(totalBytes)));
}
}
int size = applicationInfo.size();
for (int i = 0; i < size; ++i) {
Log.v("BAR CHART", "data added are " + applicationInfo.get(i).mApplicationName);
double value = Double.parseDouble(applicationInfo
.get(i).mDataUsage);
series.add("BAR", value);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series.toXYSeries());
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setDisplayChartValues(true);
renderer.setChartValuesSpacing((float) 0.5);
renderer.setColor(Color.CYAN);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.setBarSpacing(0.5);
mRenderer.getBarSpacing();
mRenderer.setXTitle("Application Number");
mRenderer.setYTitle("Data Usage");
mRenderer.setAxesColor(Color.GREEN);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setInScroll(true);
mRenderer.setLabelsColor(Color.RED);
mRenderer.addSeriesRenderer(renderer);
if (mChartViewBar == null) {
Log.v(LOG_TAG, "chart view is null");
mChartViewBar = ChartFactory
.getBarChartView(getActivity(), dataset,
mRenderer, Type.DEFAULT);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);
mChartViewBar
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartViewBar
.getCurrentSeriesAndPoint();
CategorySeries series22 =new CategorySeries("333");
mChartViewBar.repaint();
if (seriesSelection == null) {
Toast.makeText(
getActivity(),
"No chart element was clicked",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(
getActivity(),
"APPLICATION NAME : "
+ series22.getTitle()
+ 1
+ " was clicked"
+ " DATA USAGE : "
+ seriesSelection
.getXValue(),
Toast.LENGTH_SHORT).show();
}
}
});
mChartLayout.removeAllViews();
mChartLayout.addView(mChartViewBar, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
} else {
mChartLayout.removeAllViews();
mChartLayout.addView(mChartViewBar, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
mChartViewBar.repaint();
}
} else if (mPieChart) {
CategorySeries seriesPie = new CategorySeries("Pie Graph");
getActivity().startManagingCursor(c);
c.moveToPosition(-1);
while (c.moveToNext()) {
long recievedBytes = c .getLong(ApplicationDataCounterDao.CONTENT_RECEIVED_COLUMN);
Long sentBytes = c.getLong(ApplicationDataCounterDao.CONTENT_SENT_COLUMN);
totalBytes = (recievedBytes + sentBytes)
/ (1024 * 1024);
if (totalBytes > 0) {
applicationInfo
.add(new ApplicationDataUsage(
c.getString(ApplicationDataCounterDao.CONTENT_APPLICATION_NAME_COLUMN),
Double.toString(totalBytes)));
}
}
int size = applicationInfo.size();
for (ApplicationDataUsage data_value : applicationInfo) {
Log.v("PIE CHART", "data added are " + data_value.mApplicationName);
double dataUsage = Double
.parseDouble(data_value.mDataUsage);
seriesPie.add(data_value.mApplicationName, dataUsage);
}
for (int i = 0; i < size; ++i) {
prepareColors();
}
DefaultRenderer renderer = new DefaultRenderer();
for (int fillColor : colorList) {
// Log.d("1111111111",
// "FILL COLOUR TILL SIZE OF COLORLIST");
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(fillColor);
renderer.addSeriesRenderer(r);
}
renderer.setInScroll(true);
renderer.setChartTitle("APPLICATION WISE PIE CHART");
renderer.setChartTitleTextSize(20);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK);
renderer.setZoomButtonsVisible(true);
if (mChartViewPie == null) {
Log.v(LOG_TAG, "chat view is null");
// series.clear();
mChartViewPie = ChartFactory.getPieChartView(
getActivity(), seriesPie, renderer);
renderer.setClickEnabled(true);
renderer.setSelectableBuffer(10);
mChartViewPie
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartViewPie
.getCurrentSeriesAndPoint();
mChartViewPie.repaint();
if (seriesSelection == null) {
ToastHelper.showToastMessage(
"No item was Clicked",
getActivity());
} else {
ToastHelper.showToastMessage(
"Application number "
+ seriesSelection
.getPointIndex()
+ " was clicked and it's Data Usage is "
+ seriesSelection
.getValue(),
getActivity());
}
}
});
/*if (mChartViewBar != null) {
mChartLayout.removeView(mChartViewBar);
}
if (mChartViewPie != null) {
mChartLayout.removeView(mChartViewPie);
}*/
mChartLayout.addView(mChartViewPie, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
} else {
/* if (mChartViewBar != null) {
mChartLayout.removeView(mChartViewBar);
}
if (mChartViewPie != null) {
mChartLayout.removeView(mChartViewPie);
}*/
mChartLayout.removeAllViews();
mChartLayout.addView(mChartViewPie, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
mChartViewPie.repaint();
}
}
You are confusing the legend with the X axis labels. The BarChart is an XYChart which means it is getting both legend and x axis labels. The PieChart is not an XYChart, so it is not getting X axis and Y axis.
The series titles go to the legend, as you mentioned.
In the X axis the series values indexes go by default. However, you can hide the default labels and add your own custom ones:
renderer.setXLabels(0);
renderer.addXTextLabel(1, "label);
renderer.addXTextLabel(2, "label);
...