0

異なるTChartシリーズを切り替えると、実行間で凡例の表示が切り替えられると例外が発生します。例えば

  1. 棒グラフが表示されます。凡例が表示されます。
  2. 円グラフが表示されます。凡例は見えません。
  3. 棒グラフが表示されます。凡例が表示されます。
  4. クラッシュ!

これは、コントロールが再描画されたときにキャッチされない例外を引き起こす行です。

chart.getLegend().setVisible(true);

各実行の間に、私は次のことを行います。

chart.setAutoRepaint(false);
chart.removeAllSeries();
// Build chart...
chart.setAutoRepaint(true);
chart.refreshControl();

TChart専門家の皆さん、どうすればこのクラッシュを回避できますか?

4

1 に答える 1

1

これは私にとってクラッシュしていません。問題なくバーからパイに数回切り替えることができます。

package com.steema.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Spinner;

import com.steema.teechart.TChart;
import com.steema.teechart.styles.Bar;
import com.steema.teechart.styles.Pie;
import com.steema.teechart.themes.ThemesList;

public class AndroidTestActivity extends Activity implements OnItemSelectedListener{

    private TChart tChart1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout group = (LinearLayout) findViewById(R.id.linearLayoutTchart);

        tChart1 = new TChart(this);
        group.addView(tChart1);
        ThemesList.applyTheme(tChart1.getChart(), 1);

        Spinner spinner = (Spinner) findViewById(R.id.series_spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.series_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        tChart1.setAutoRepaint(false);
        tChart1.removeAllSeries();
        switch (arg2) {
        case 0:
            Bar bar1 = new Bar(tChart1.getChart());
            bar1.fillSampleValues();
            tChart1.getLegend().setVisible(true);
            break;
        case 1:
            Pie pie1 = new Pie(tChart1.getChart());
            pie1.fillSampleValues();
            tChart1.getLegend().setVisible(false);
            break;
        }
        tChart1.setAutoRepaint(true);
        tChart1.refreshControl();
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {

    }
}

ここに私のmain.xmlがあります:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"/>
    <Spinner android:id="@+id/series_spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <LinearLayout android:id="@+id/linearLayoutTchart" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>
</LinearLayout>

そしてここで私のstrings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">TeeChartJava for Android testing application!</string>
    <string name="app_name">AndroidTest</string>
    <string-array name="series_array">
        <item>Bar</item>
        <item>Pie</item>
    </string-array>
</resources>

更新 1:tChart1.getLegend().setSeries(tChart1.getSeries(0));上記の int he を追加するとcase 1:

    case 1:
        Pie pie1 = new Pie(tChart1.getChart());
        pie1.fillSampleValues();
        tChart1.getLegend().setSeries(tChart1.getSeries(0));
        tChart1.getLegend().setVisible(false);
        break;

その後、Bar シリーズを選択し直すとエラー メッセージが表示されます。これは、円グラフ シリーズを使用するように凡例を設定したためです (最初に円グラフを選択したとき)。バーを選択したときにその円グラフ シリーズを削除しましたが、凡例は削除された円グラフ シリーズを引き続き参照しています。凡例に有効なシリーズが設定されていることを確認してください。すなわち:

    case 0:
        Bar bar1 = new Bar(tChart1.getChart());
        bar1.fillSampleValues();
        tChart1.getLegend().setSeries(tChart1.getSeries(0));
        tChart1.getLegend().setVisible(true);
        break;
    case 1:
        Pie pie1 = new Pie(tChart1.getChart());
        pie1.fillSampleValues();
        tChart1.getLegend().setSeries(tChart1.getSeries(0));
        tChart1.getLegend().setVisible(false);
        break;

シリーズリストをクリアすると、次のバージョンが設定さgetLegend().setSeries(null)れます。removeAllSeries()

于 2013-01-07T13:37:49.503 に答える