Menu

Handle ChartFormatHandler

This section provides information on customizing the configuration of a particular label in the graph view. Using this interface, app can modify the style of a particular ChartValues / X axis label / Y axis label.

Perform the following steps to create a customized label based on particular condition or event.

1. Implement the required methods of ChartFormatListener interface and return true. If a particular method is not implemented, return false.

2. App must register the chart format listener for the graph view.

View lineChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);
lineChartView.addDrawChartLabelsListener(this);

3. Customize the X and Y axis labels through the app. An activity/fragment must “implements ChartFormatListener” and override the following methods.

@Override
public boolean drawChartPointLabels(Canvas canvas, double d, double e, float xPosition, float yPosition, int seriesIndex, Rect screenLayout) {
 return false;
}

@Override
public boolean drawChartXLabel(Canvas canvas, double d, float xPosition, float yPosition, int scaleIndex) {
 if (d % 4 == 0) {
  return false;
 } else {
  Paint p = new Paint();
  p.setTextAlign(Align.CENTER);
  p.setColor(Color.RED);
  canvas.drawText("(" + String.valueOf(d) + ")", xPosition, yPosition, p);
  return true;
 }
 return false;
}
@Override
public boolean drawChartYLabel(Canvas canvas, double d, float xPosition, float yPosition, int scaleIndex, float angle) {

 if (d % 20 == 0) {
  return false;
 } else {
  Paint p = new Paint();
  p.setTextAlign(Align.RIGHT);
  p.setColor(Color.RED);
  canvas.drawText("(" + String.valueOf(d) + ")", xPosition, yPosition, p);
  return true;
 }
 return false;
}

Output

Items highlighted in blue color rectangle are the custom labels defined by the app.