0

アプリケーションでAndroid プロット チャート ライブラリバー レンダリング チャートを使用しています。グラフの描画時に遷移アニメーションを適用したい。

例: 棒グラフは、グラフの 0 から現在の値まで滑らかに上昇しています。

これを達成するのを手伝ってください。

前もって感謝します。

4

1 に答える 1

1

Keshaw の言うとおりです。「組み込み」のアニメーション効果はありませんが、ライブラリはリアルタイム表示用に設計されているため、独自の効果を作成することは難しくありません。DemoApp の SimpleXYPlot の例の上に一緒にスローされた機能する例を次に示します (AnimatedSeries の実装は、あなたが興味を持っている部分です)。

/**
 * A straightforward example of using AndroidPlot to plot some data.
 */
public class SimpleXYPlotActivity extends Activity
{

    private XYPlot plot;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.simple_xy_plot_example);

        // initialize our XYPlot reference:
        plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

        // Create a couple arrays of y-values to plot:
        Number[] series1Numbers = {1, 8, 5, 2, 7, 4};
        Number[] series2Numbers = {4, 6, 3, 8, 2, 10};

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

        // same as above
        XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");

        // Create a formatter to use for drawing a series using LineAndPointRenderer
        // and configure it from xml:
        LineAndPointFormatter series1Format = new LineAndPointFormatter();
        series1Format.setPointLabelFormatter(new PointLabelFormatter());
        series1Format.configure(getApplicationContext(),
                R.xml.line_point_formatter_with_plf1);

        AnimatedSeries as1 = new AnimatedSeries(plot, series1);

        // add a new series' to the xyplot:
        plot.addSeries(as1, series1Format);

        // same as above:
        LineAndPointFormatter series2Format = new LineAndPointFormatter();
        series2Format.setPointLabelFormatter(new PointLabelFormatter());
        series2Format.configure(getApplicationContext(),
                R.xml.line_point_formatter_with_plf2);
        plot.addSeries(series2, series2Format);

        // reduce the number of range labels
        plot.setTicksPerRangeLabel(3);
        plot.getGraphWidget().setDomainLabelOrientation(-45);

        new Thread(as1).start();
    }

    /**
     * A primitive example of applying an animation to a series
     */
    class AnimatedSeries implements XYSeries, Runnable {

        private final XYPlot plot;
        private final XYSeries series;
        private int step = 0;
        private int stepCount = 25;
        private float factor = 0;

        public AnimatedSeries(XYPlot plot, XYSeries series) {
            this.plot = plot;
            this.series = series;
        }

        @Override
        public void run() {
            try {
                while (step < stepCount) {
                    factor = step / (float) stepCount;
                    Thread.sleep(50);
                    plot.redraw();
                    step++;
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public int size() {
            return series.size();
        }

        @Override
        public Number getX(int index) {
            return index;
        }

        @Override
        public Number getY(int index) {
            return series.getY(index).doubleValue() * factor;
        }

        @Override
        public String getTitle() {
            return series.getTitle();
        }
    }
}
于 2014-04-17T18:18:00.230 に答える