Android achartengine 渲染饼图有不必要的线条
Android achartengine rendering pie chart with unnecessary line
我正在使用 achartengine 来渲染饼图,图表已渲染但与图表一起在大屏幕设备上似乎有一条线。 (如 5.5 英寸)。
该线位于红色矩形中。 (我画了矩形来指出不需要的线)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/item_selector_of_lists"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:paddingTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/chart_layout"/>
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="@+id/dummyLayout" >
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="@drawable/ic_tic"
android:visibility="gone"
android:id="@+id/tick_image" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/helper"
android:layout_toRightOf="@+id/chart_layout"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/chart_layout"
android:layout_toLeftOf="@+id/date_tv"
android:layout_toStartOf="@+id/date_tv"
android:gravity="center|left">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Large Text"
android:layout_gravity="center"
android:textColor="@android:color/black"
android:id="@+id/list_name"
android:gravity="center_vertical"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/date_tv"
android:textStyle="italic"
android:textColor="@color/gray"
android:layout_marginRight="10dp"
android:layout_alignBottom="@+id/helper"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Java 代码段:
private void initData(RelativeLayout chartLayout, double uncompleted, double completed) {
if (uncompleted == 0) {
completed = 1;
}
double[] values = {uncompleted,completed };
String[] colors = {//uncompleted, completed
"#82CA9C", "#F5F0ED"
};
CategorySeries series = new CategorySeries("");
int length = values.length;
for (int i = 0; i < length; i++) {
series.add(values[i]);
}
DefaultRenderer renderer = new DefaultRenderer();
for (int i = 0; i < length; i++) {
SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
seriesRenderer.setColor(Color.parseColor(colors[i]));
renderer.addSeriesRenderer(seriesRenderer);
}
// renderer.setAxesColor(Color.TRANSPARENT);
// renderer.setBackgroundColor(Color.parseColor("#82CA9C"));
renderer.setLabelsColor(Color.TRANSPARENT);
drawChart(series, renderer, chartLayout);
}
private void drawChart(CategorySeries series,
DefaultRenderer renderer, RelativeLayout chartLayout) {
GraphicalView mGraphView = null;
mGraphView =
ChartFactory.getPieChartView(context, series, renderer);
chartLayout.addView(mGraphView);
}
尝试将 renderer.setShowLabels(false);
和 renderer.setShowLegend(false);
添加到您的代码中。这将隐藏图例和标签。您在代码中使颜色透明的标签,您可以完全隐藏它们。
我正在使用 achartengine 来渲染饼图,图表已渲染但与图表一起在大屏幕设备上似乎有一条线。 (如 5.5 英寸)。 该线位于红色矩形中。 (我画了矩形来指出不需要的线)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/item_selector_of_lists"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:paddingTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/chart_layout"/>
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="@+id/dummyLayout" >
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="@drawable/ic_tic"
android:visibility="gone"
android:id="@+id/tick_image" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/helper"
android:layout_toRightOf="@+id/chart_layout"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/chart_layout"
android:layout_toLeftOf="@+id/date_tv"
android:layout_toStartOf="@+id/date_tv"
android:gravity="center|left">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Large Text"
android:layout_gravity="center"
android:textColor="@android:color/black"
android:id="@+id/list_name"
android:gravity="center_vertical"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/date_tv"
android:textStyle="italic"
android:textColor="@color/gray"
android:layout_marginRight="10dp"
android:layout_alignBottom="@+id/helper"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Java 代码段:
private void initData(RelativeLayout chartLayout, double uncompleted, double completed) {
if (uncompleted == 0) {
completed = 1;
}
double[] values = {uncompleted,completed };
String[] colors = {//uncompleted, completed
"#82CA9C", "#F5F0ED"
};
CategorySeries series = new CategorySeries("");
int length = values.length;
for (int i = 0; i < length; i++) {
series.add(values[i]);
}
DefaultRenderer renderer = new DefaultRenderer();
for (int i = 0; i < length; i++) {
SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
seriesRenderer.setColor(Color.parseColor(colors[i]));
renderer.addSeriesRenderer(seriesRenderer);
}
// renderer.setAxesColor(Color.TRANSPARENT);
// renderer.setBackgroundColor(Color.parseColor("#82CA9C"));
renderer.setLabelsColor(Color.TRANSPARENT);
drawChart(series, renderer, chartLayout);
}
private void drawChart(CategorySeries series,
DefaultRenderer renderer, RelativeLayout chartLayout) {
GraphicalView mGraphView = null;
mGraphView =
ChartFactory.getPieChartView(context, series, renderer);
chartLayout.addView(mGraphView);
}
尝试将 renderer.setShowLabels(false);
和 renderer.setShowLegend(false);
添加到您的代码中。这将隐藏图例和标签。您在代码中使颜色透明的标签,您可以完全隐藏它们。