Вопрос

I am using android plot for plotting my dynamic date. Can anyone tell me how i can change the width of the sine wave in the below picture.

enter image description here

I am using sample code for a Dynamic XY Plot.

And code below is my activity.

public class MyActivity extends Activity {

// redraws a plot whenever an update is received:
private class MyPlotUpdater implements Observer {
    Plot plot;
    public MyPlotUpdater(Plot plot) {
        this.plot = plot;
    }
    @Override
    public void update(Observable o, Object arg) {
        try {
            plot.postRedraw();
        } catch (InterruptedException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

private XYPlot dynamicPlot;
private XYPlot staticPlot;
private MyPlotUpdater plotUpdater;

@Override
public void onCreate(Bundle savedInstanceState) {

    // android boilerplate stuff
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // get handles to our View defined in layout.xml:
    dynamicPlot = (XYPlot) findViewById(R.id.dynamicPlot);

    plotUpdater = new MyPlotUpdater(dynamicPlot);

    // only display whole numbers in domain labels
    dynamicPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));

    // getInstance and position datasets:
    SampleDynamicXYDatasource data = new SampleDynamicXYDatasource();
    SampleDynamicSeries sine1Series = new SampleDynamicSeries(data, 0, "Sine 1");
    SampleDynamicSeries sine2Series = new SampleDynamicSeries(data, 1, "Sine 2");

    dynamicPlot.addSeries(sine1Series, new LineAndPointFormatter(Color.rgb(0, 0, 0), null, Color.rgb(0, 80, 0)));

    // create a series using a formatter with some transparency applied:
    LineAndPointFormatter f1 = new LineAndPointFormatter(Color.rgb(0, 0, 200), null, Color.rgb(0, 0, 80));
    f1.getFillPaint().setAlpha(220);
    dynamicPlot.addSeries(sine2Series, f1);
    dynamicPlot.setGridPadding(5, 0, 5, 0);

    // hook up the plotUpdater to the data model:
    data.addObserver(plotUpdater);

    dynamicPlot.setDomainStepMode(XYStepMode.SUBDIVIDE);
    dynamicPlot.setDomainStepValue(sine1Series.size());

    // thin out domain/range tick labels so they dont overlap each other:
    dynamicPlot.setTicksPerDomainLabel(5);
    dynamicPlot.setTicksPerRangeLabel(3);
    dynamicPlot.disableAllMarkup();

    // freeze the range boundaries:
    dynamicPlot.setRangeBoundaries(-100, 100, BoundaryMode.FIXED);

    // kick off the data generating thread:
    new Thread(data).start();
}

}

Это было полезно?

Решение

In the file SampleDynamicXYDatasource.java you can find the line

double amp = sinAmp * Math.sin(index + phase + 4);

There the sine wave is generated. By belating the index (e.g. by multiplying it with 0.5), you can make the sine wave's period larger, or in graphics speak, scale it on the x axis.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top