3

単純なXY折れ線グラフをアクティビティに統合したいと思います。カスタマイズ(カスタマイズ可能な背景、色、軸ラベル)を使用した無料のグラフを探しているときに、AchartengineとAdnroidplotの2つの候補を見つけました。他にもいくつかのライブラリがありましたが、それらはカスタマイズできないか、個別のインテントとしてのみ使用できませんでした。

古いAndroidAPIのサポートも必要です(少なくとも1.6がサポートされている必要があります)。

Achartengineを試しましたが、ScrollViewに統合すると失敗しました。スクロールしていると、チャートがなんらかの形で破損し、絞り込まれ、背景要素が漂っているように見えました。

それから私はAdnroidplotを試しました。最初は、Pairクラスのため、1.6では開始されませんでした。しかし、Adnroidplotフォーラムで問題の修正を見つけました。カスタムオブザーバーは正常に機能しましたが、動的な更新もすべて正常に機能しているように見えました。X軸ラベルをカスタマイズするのは少し難しかったです(数字ではなくカスタム文字列が必要でした)が、カスタムフォーマッターを使用して最終的にそれを行いました。

しかし、それから私はクライアントのデータベースからの実際のデータでそれを試しました。値が等しい一連のポイントがいくつかありました。そして、Adnroidplotが水平線を描画できない、ハングする、またはチャートを完全に台無しにするのを見てショックを受けました!

これがテストケースです。AdnroidplotQuickstartから借用し、小さな変更を加えて、同じ値の1つのシリーズを作成しました。

pricesPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

// Create array of y-values to plot:
Number[] series1Numbers = {7, 7}; // horizontal line expected, got nothing or hang

// Turn the above arrays into XYSeries:
XYSeries series1 = new SimpleXYSeries(
    Arrays.asList(series1Numbers),          // SimpleXYSeries takes a List so turn our array into a List
    ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
            "Series1");                             // Set the display title of the series

// Create a formatter to use for drawing a series using LineAndPointRenderer:
LineAndPointFormatter series1Format = new LineAndPointFormatter(
            Color.rgb(0, 200, 0),                   // line color
            Color.rgb(0, 100, 0),                   // point color
            null);              // fill color (optional) <- my app hangs if I add it for a horizontal line

// Add series1 to the xyplot:
pricesPlot.addSeries(series1, series1Format);

// Reduce the number of range labels
pricesPlot.setTicksPerRangeLabel(3);

// By default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
pricesPlot.disableAllMarkup();

私はすでにAdnroidplotフォーラムに投稿しましたが、彼らがどれだけ早く答え、いつ問題が修正されるかはわかりません。

だから私はStackOverflowの誰かがそれの回避策を知っているかもしれないと思いますか?

4

3 に答える 3

3

Androidplot フォーラムの開発者のおかげで、解決策を得ることができました。次のコードは、Activity.java ファイルの一部です。残念ながら、最終的なコードは後でリファクタリングされ、いくつかの部分はカスタム データソースとカスタム XYSeries に移動されましたが、ここで公開する権限はありません。

このコードは Androidplot-core-0.4.4-release.jar で機能しましたが、それ以降のバージョンで機能するかどうかはわかりません。

// for chart
private XYPlot pricesPlot;

/** Called when the activity is first created. */   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // ... other initialisation code omitted for brevity ...

    pricesPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

    // the following code was added as a debug code to test that it works.
    // later many things were changed, so take it "as is" - this was the core of the solution

    PriceDatesFormat ppf = new PriceDatesFormat();
    ppf.Labels = new String[]{
                "2011-01",
                "2011-05",              
                "2011-07",
                "2011-11",
                "2011-07",
                "2011-07"                       
        }; 

    pricesPlot.getGraphWidget().setDomainValueFormat(ppf);       

    // Create two arrays of y-values to plot:
    Float [] seriesNumbers = new Float[]{118f, 185f};

   Float min = Collections.min(Arrays.asList(seriesNumbers));
   Float max = Collections.max(Arrays.asList(seriesNumbers));  

   pricesPlot.setRangeBoundaries(min - 0.1*min, max + 0.1*max, BoundaryMode.AUTO);// make them a bit wider out of min/max values
于 2012-02-03T18:21:03.003 に答える
1

AChartEngine を使用して ScrollView 内でチャートを圧迫する問題をグーグルで検索した人にとって、これは問題の解決策です。

renderer.setInScroll(true);
于 2014-12-04T12:25:31.347 に答える