0

我在我的应用程序中使用 AchartEngine。是否可以更换传说。

它的水平

oA oB oC oD

但我想让它垂直

OA
oB
oC
外径

是否可以更改图例的位置?任何帮助将不胜感激。

4

3 回答 3

0

我通过 hack 解决了这个问题。(这是我/distinguished/职业生涯中的第一次!)

见证:

xySeries.setTitle(legend + "                                                                                                                                   ");

图表测量空间,认为它没有水平空间,并垂直堆叠图例。

于 2020-04-15T20:26:49.080 回答
0

Then I took the spaces out and made a lower level hack. Inside AbstractChart.java, function drawLegend(), adjust this block:

            if (true) { // i > 0 && getExceed(currentWidth, renderer, right, width)) {
              currentX = left;
              currentY += renderer.getLegendTextSize();
              size += renderer.getLegendTextSize();
              currentWidth = currentX + extraSize;
            }

Someone could easily make a real feature out of that if they need various charts with various legend orientations.

于 2020-04-15T20:37:53.763 回答
-2

我没有使用 AchartEngine 而是动态地创建类似的东西。在此处输入图像描述

这里是示例 java 代码。

public class MainActivity extends Activity {

private LinearLayout linear;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Random randomGenerator = new Random();
    for (int i = 0; i < 100; i++) {
        linear = (LinearLayout) findViewById(R.id.linear);
        LinearLayout lay = new LinearLayout(this);
        LinearLayout lay1 = new LinearLayout(this);
        TextView text = new TextView(this);
        text.setText("ONES");
        text.setTextColor(Color.parseColor("#000000"));
        text.setLayoutParams(new LinearLayout.LayoutParams(60, 40));

        TextView line = new TextView(this);
        line.setBackgroundColor(Color.parseColor("#00FF00"));
        line.setLayoutParams(new LinearLayout.LayoutParams(5, 90));

        TextView btn = new TextView(this);
        int randomInt = randomGenerator.nextInt(100);
        if (randomInt > 0 && randomInt <= 10) {
            btn.setBackgroundColor(Color.parseColor("#FF1919"));
        } else if (randomInt > 10 && randomInt <= 20) {
            btn.setBackgroundColor(Color.parseColor("#C41300"));
        } else if (randomInt > 20 && randomInt <= 30) {
            btn.setBackgroundColor(Color.parseColor("#AB1100"));
        } else if (randomInt > 30 && randomInt <= 40) {
            btn.setBackgroundColor(Color.parseColor("#7A0C00"));
        } else if (randomInt > 40 && randomInt <= 50) {
            btn.setBackgroundColor(Color.parseColor("#3E0600"));
        } else if (randomInt < 50 && randomInt <= 60) {
            btn.setBackgroundColor(Color.parseColor("#000000"));
        } else if (randomInt > 60 && randomInt <= 70) {
            btn.setBackgroundColor(Color.parseColor("#003E0F"));

        } else if (randomInt > 70 && randomInt <= 80) {
            btn.setBackgroundColor(Color.parseColor("#007A1D"));

        } else if (randomInt > 80 && randomInt <= 90) {
            btn.setBackgroundColor(Color.parseColor("#00C42F"));

        } else {
            btn.setBackgroundColor(Color.parseColor("#11FF4A"));

        }
        Log.d("TAG", "randnumber" + randomInt);

        btn.setLayoutParams(new LinearLayout.LayoutParams(randomInt, 40));

        btn.setId(i);
        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Log.d("TAG", "get id" + arg0.getId());
            }
        });
        TextView text1 = new TextView(this);
        text1.setText("1");
        text1.setTextColor(Color.parseColor("#000000"));
        text1.setLayoutParams(new LinearLayout.LayoutParams(60, 40));
        lay1.setOrientation(LinearLayout.HORIZONTAL);
        lay1.setGravity(Gravity.CENTER_VERTICAL);
        // lay1.setPadding(0, 10, 0, 10);
        lay1.addView(text);
        lay1.addView(line);
        lay1.addView(btn);
        lay1.addView(text1);
        lay.setOrientation(LinearLayout.VERTICAL);
        lay.addView(lay1);
        linear.addView(lay);
    }
}

}

这是xml代码。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical" >

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

于 2013-09-04T14:14:55.383 回答