- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
UPDATE: All done! The LinearLayout needed an actual height and width to it. I'm sure I shouldn't need to add them but at least it gives me something to work with. Ta. I would have self answered this but I haven't got enough of a reputation apparently and need to wait 8 hours. I had spent days trying to sort this out, post the question and work it out in 2 hours. Soz.
我觉得我做错了什么。我看过一些示例,并认为我在做几乎相同的事情 - 但显然不是。
更新:应该指出,我正在使用 aChartEngine 图形库将 PieChartView 添加到 LinearLayout
我有一个方法
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
if(renderer==null)
renderer = new DefaultRenderer();
renderer.setClickEnabled(true);
renderer.setZoomEnabled(true);
renderer.setSelectableBuffer(10);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 20, 30, 15, 0 });
renderer.setZoomButtonsVisible(true);
renderer.setStartAngle(90);
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
像这样在 onCreate() 中调用
MyDataSource dataSource = new MyDataSource(this);
dataSource.open();
dataSet = new CategorySeries("Analysis");
int i = 0;
for(String category:categoriesArray){
dataSet.add(category, dataSource.getTotalForCategory(category).getNumbers().doubleValue());
colors[i]=listOfColours[i];
i++;
}
dataSource.close();
buildCategoryRenderer(colors);
然后在 onResume() 中
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if(graph==null){
graph = ChartFactory.getPieChartView(this, dataSet, renderer);
LinearLayout graphLayout = (LinearLayout)findViewById(R.id.all_graph);
graphLayout.addView(graph, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}else{
graph.repaint();
}
}
这是我的xml布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:scrollbars="vertical">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/summary_table" >
<LinearLayout android:id="@+id/all_graph"
android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1">
</LinearLayout>
<LinearLayout android:background="@android:drawable/list_selector_background" android:id="@+id/current_foo_row">
<TextView
android:id="@+id/foos_current_foo"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:text="@string/current"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"
/>
<TextView
android:id="@+id/current_foo_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_weight="0.4"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"/>
<ImageView
android:layout_width="0px"
android:layout_height="fill_parent"
android:src="@android:drawable/ic_menu_more"
android:contentDescription="@string/more"
android:layout_weight="0.1"/>
</LinearLayout>
<!-- Hidden bar in/Spend -->
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/bar_spend_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/bar_spend"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/bar_spend"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"
/>
<TextView
android:id="@+id/bar_spend_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/bar_in_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/bar_in"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/bar_in"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/bar_in_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<!-- FINISH -->
<LinearLayout android:background="@android:drawable/list_selector_background" android:id="@+id/maybe_foo_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/foos_month_expected_foo"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:text="@string/expected"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"
/>
<TextView
android:id="@+id/maybe_foo_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_weight="0.4"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"/>
<ImageView
android:layout_width="0px"
android:layout_height="fill_parent"
android:src="@android:drawable/ic_menu_more"
android:contentDescription="@string/more"
android:layout_weight="0.1"/>
</LinearLayout>
<!-- Hidden bar in/Spend -->
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/remaining_spend_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/remaining_spend"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/remaining_spend"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/remaining_spend_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="0px" android:visibility="gone" android:background="@drawable/back" android:id="@+id/remaining_in_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/remaining_in"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/remaining_in"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/remaining_in_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<!-- FINISH -->
<LinearLayout >
<Button
android:id="@+id/foos_add_transaction_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="@string/add_transaction"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
</TableLayout>
结果是图表没有显示。有什么想法吗?
最佳答案
LinearLayout 需要一个实际的高度和宽度。我确定我不需要添加它们,但至少它给了我一些可以使用的东西。
关于android - AChartEngine 饼图 View 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11189529/
有人可以帮我理解为什么我的饼图百分比计算不正确吗?看截图: 根据我的计算,如 RHS 上所示,支出百分比应为 24.73%。传递给 Highcharts 的值如下:- 花费:204827099.36-
我正在制作圆环饼图。 我设置数据的颜色并获取钻取(它是保存外部切片的数据和配置的对象)切片的颜色为同一组颜色。我想设置要在向下钻取对象中使用的不同颜色数组。请参阅附图(外层切片有两种颜色:橙色和透明)
我是一名优秀的程序员,十分优秀!