AChart Engine : How to set every label in the chart to support multi screen resolution.


How to set every label in the chart to support multi screen resolution.

This is my implement

public static XYMultipleSeriesRenderer setRendererLabelSize(Context context,
                                                            XYMultipleSeriesRenderer renderer)
{
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float textSize;
float textSizeMini;

switch (context.getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_XHIGH:
renderer.setMargins(new int[]{40, 60, 25, 10});
textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_XHDPI,
metrics);
textSizeMini = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_XHDPI_MINI,
metrics);
break;
case DisplayMetrics.DENSITY_HIGH:
renderer.setMargins(new int[]{30, 50, 20, 10});
textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_HDPI,
metrics);
textSizeMini = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_HDPI_MINI,
metrics);
break;
default:
renderer.setMargins(new int[]{30, 50, 20, 10});
textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_MDPI,
metrics);
renderer.setAxisTitleTextSize(textSize);
textSizeMini = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
PConstant.Chart.TEXT_SIZE_MDPI_MINI,
metrics);
break;
}

renderer.setAxisTitleTextSize(textSize);
renderer.setLegendTextSize(textSizeMini);
//renderer.setChartTitleTextSize(textSize);
//the num in the axis
renderer.setLabelsTextSize(textSizeMini);
return renderer;
}


The PConstant.Chart is the Class that store constant of LabelSize
public static class Chart {
public static final int TEXT_SIZE_XHDPI = 17;
public static final int TEXT_SIZE_HDPI = 15;
public static final int TEXT_SIZE_MDPI = 14;

public static final int TEXT_SIZE_XHDPI_MINI = 14;
public static final int TEXT_SIZE_HDPI_MINI = 12;
public static final int TEXT_SIZE_MDPI_MINI = 11;

}

Popular posts from this blog

เทคนิค ชนะ เกมเศรษฐี 14 ตารวด!!! ( Let's get Rich )

Using Google Chrome Inspect Element to Analyze the website

Easy way to download whole youtube play list and convert them to mp3