I am using a MarkerView class to show markerviews in the chart. The markerview layout I have created contains two textview, one below the other.
The problem I am facing is that the markerview for the last point on the chart is half within the chart and half outside the chart. The two images below state the problem clearly :
The first image shows a markerview for a point in the center of the chart which shows without any problem :
The second image, as shown below, shows the markerview for the last point of the chart, which is half within the chart.
How do I get this markerview to adjust so that it shows within the chart area.
The wiki does not state any customizations for the markerview. Are there any more customizations?
Also, in case of a multiple line chart, if I click only on one of the line points, the markerview comes without a problem. But if I click for the markerview on any point on the other line, the application fails. Any idea why this happens.
The code for the markerview class is given below :
public class TooltipView extends MarkerView {
private BaseGraphMetadata mBaseGraphMetadata;
private TextView mTooltipDate, mTooltipValue;
public TooltipView(Context context, int layoutResource, BaseGraphMetadata baseGraphMetadata) {
super(context, layoutResource);
mTooltipDate = (TextView)findViewById(R.id.tooltip_date);
mTooltipValue = (TextView)findViewById(R.id.tooltip_value);
mBaseGraphMetadata = baseGraphMetadata;
}
@Override
public void refreshContent(Entry entry, int i) {
List<DrillDownInfo> drillDownInfoList = (List<DrillDownInfo>) entry.getData();
DrillDownInfo drillDownInfo = drillDownInfoList.get(i);
Map<String, String> group = drillDownInfo.getGroupByNameVsGroupByValue();
Iterator iterator = group.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry pair = (Map.Entry)iterator.next();
if(pair.getKey()!=null && pair.getValue()!=null) {
String key = (String) pair.getKey();
key = key.toUpperCase();
Double value = Double.parseDouble((String) pair.getValue());
String formattedValue = mBaseGraphMetadata.getDataFormatter().getFormattedValue(value);
mTooltipDate.setText(key + " : " + formattedValue);
}
iterator.remove();
}
mTooltipValue.setText(String.valueOf("VALUE : "+entry.getVal()));
}
@Override
public int getXOffset() {
return -(getWidth() / 2);
}
@Override
public int getYOffset() {
return -getHeight();
}
}
I have found a simple solution to this issue. You need to set chart in your custom marker view as below:
setChartView(chart);
..and override the draw method as below:
@Override
public void draw(Canvas canvas, float posX, float posY) {
super.draw(canvas, posX, posY);
getOffsetForDrawingAtPoint(posX, posY);
}