MPAndroidChart如何制作曲线图?

时间:2017-07-14 13:35:11

标签: android mpandroidchart android-graphview

我正在使用MPAndroidChart制作太阳运动图并在白天标记不同点。此时它看起来像这样:enter image description here

当我将其更改为dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);时 它不会让它看起来很奇怪:

enter image description here

顶部的变化很小。当我做dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);

它也有这种奇怪的循环效果。

我做错了什么,我的图表上的点是错的吗?

我想得到这种效果: enter image description here

请帮忙,谢谢

修改

这是我使用的代码

public class TestingZone extends Activity {

DocumentView documentView;
TextView textView;
ComplexZmanimCalendar czc;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.testingzone);



    czc = DataVariables.getInstance().getCzc();
//        czc.getCalendar().set(2017, Calendar.JUNE, 21);
        czc.getCalendar().set(2017, Calendar.DECEMBER, 21);


    float alosX = getXPosition(czc.getAlos16Point1Degrees());
    float alosY = getYPosition(czc.getAlos16Point1Degrees());

    float zmanTallisAndTefillinX = getXPosition(czc.getMisheyakir10Point2Degrees());
    float zmanTallisAndTefillinY = getYPosition(czc.getMisheyakir10Point2Degrees());

    float netzHaChamaX = getXPosition(czc.getSunrise());
    float netzHaChamaY = getYPosition(czc.getSunrise());

    float sofZmanShemahMagenAvrahamX = getXPosition(czc.getSofZmanShmaMGA16Point1Degrees());
    float sofZmanShemahMagenAvrahamY = getYPosition(czc.getSofZmanShmaMGA16Point1Degrees());

    float sofZmanShemahGraX = getXPosition(czc.getSofZmanShmaGRA());
    float sofZmanShemahGraY = getYPosition(czc.getSofZmanShmaGRA());

    float sofZmanTefillaX = getXPosition(czc.getSofZmanTfilaGRA());
    float sofZmanTefillaY = getYPosition(czc.getSofZmanTfilaGRA());

    float chatzosX = getXPosition(czc.getChatzos());
    float chatzosY = getYPosition(czc.getChatzos());

    float minchaGedolaX = getXPosition(czc.getMinchaGedola());
    float minchaGedolaY = getYPosition(czc.getMinchaGedola());

    float plagHaMinchaX = getXPosition(czc.getPlagHamincha());
    float plagHaMinchaY = getYPosition(czc.getPlagHamincha());

    float shkiahX = getXPosition(czc.getSunset());
    float shkiahY = getYPosition(czc.getSunset());

    float tzesHakochavimX = getXPosition(czc.getTzais());
    float tzesHakochavimY = getYPosition(czc.getTzais());




    LineChart chart = (LineChart) findViewById(R.id.chart);

    List<Entry> entries = new ArrayList<Entry>();


    entries.add(new Entry(alosX, alosY));
    entries.add(new Entry(zmanTallisAndTefillinX, zmanTallisAndTefillinY));
    entries.add(new Entry(netzHaChamaX, netzHaChamaY));
    entries.add(new Entry(sofZmanShemahMagenAvrahamX, sofZmanShemahMagenAvrahamY));
    entries.add(new Entry(sofZmanShemahGraX, sofZmanShemahGraY));
    entries.add(new Entry(sofZmanTefillaX, sofZmanTefillaY));
    entries.add(new Entry(chatzosX, chatzosY));
    entries.add(new Entry(minchaGedolaX, minchaGedolaY));
    entries.add(new Entry(plagHaMinchaX, plagHaMinchaY));
    entries.add(new Entry(shkiahX, shkiahY));
    entries.add(new Entry(tzesHakochavimX, tzesHakochavimY));


    Log.d("alos", "` "+ " X: " +alosX + " Y: " + alosY);
    Log.d("zmanTallisAndTefillin", "` "+ " X: " +zmanTallisAndTefillinX + " Y: " + zmanTallisAndTefillinY);
    Log.d("netzHaChama", "` "+ " X: " +netzHaChamaX + " Y: " + netzHaChamaY);
    Log.d("sofZmanShemahMagenAvrah", "` "+ " X: " +sofZmanShemahMagenAvrahamX + " Y: " + sofZmanShemahMagenAvrahamY);
    Log.d("sofZmanShemahGra", "` "+ " X: " +sofZmanShemahGraX + " Y: " + sofZmanShemahGraY);
    Log.d("sofZmanTefilla", "` "+ " X: " +sofZmanTefillaX + " Y: " + sofZmanTefillaY);
    Log.d("chatzos", "` "+ " X: " +chatzosX + " Y: " + chatzosY);
    Log.d("minchaGedola", "` "+ " X: " +minchaGedolaX + " Y: " + minchaGedolaY);
    Log.d("plagHaMincha", "` "+ " X: " +plagHaMinchaX + " Y: " + plagHaMinchaY);
    Log.d("shkiah", "` "+ " X: " +shkiahX + " Y: " + shkiahY);
    Log.d("tzesHakochavim", "` "+ " X: " +tzesHakochavimX + " Y: " + tzesHakochavimY);



    LineDataSet dataSet = new LineDataSet(entries, "Label");

    dataSet.setColor(Color.BLUE);
    dataSet.setCircleColor(Color.BLACK);
    dataSet.setCircleRadius(10f);
    dataSet.setLineWidth(5f);
    dataSet.setDrawValues(false);
    dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    dataSet.setCubicIntensity(.2f);

    LineData lineData = new LineData(dataSet);

    chart.setData(lineData);
//        chart.getXAxis().setDrawGridLines(false);
//        chart.getXAxis().setEnabled(false);

//        chart.getAxisLeft().setDrawGridLines(false);
//        chart.getAxisLeft( ).setEnabled(false);
//        chart.getAxisRight().setDrawGridLines(false);
//        chart.getAxisRight().setEnabled(false);

    chart.setDragEnabled(false);
    chart.setScaleEnabled(false);
    chart.setScaleXEnabled(false);
    chart.setScaleYEnabled(false);
    chart.setPinchZoom(false);
    chart.setDoubleTapToZoomEnabled(false);
    chart.setDragDecelerationEnabled(false);

    chart.getAxisLeft().setInverted(true);
//        chart.setBackgroundColor(Color.TRANSPARENT);
//        chart.getAxisLeft().setDrawLabels(false);
//        chart.getAxisRight().setDrawLabels(false);
//        chart.getXAxis().setDrawLabels(false);
//        chart.getLegend().setEnabled(false);
//        chart.getDescription().setEnabled(false);

    chart.invalidate(); // refresh
}


public float getTime(Date dateTime) {

    float hours = dateTime.getHours();
    float minutes = dateTime.getMinutes() / 60.0f;
    float time = hours + minutes;
    return time;
}


public float getXPosition(Date dateTime) {

    float time = getTime(dateTime) + 0.0f;
    float chatzosTime = getTime(czc.getChatzos()) + 0.0f;
    float xPosition = 0.0f;
    float percentageX = 0.0f;

    Log.d("X hours: ", "" + time);

    Log.d("X Chatzos", "" + chatzosTime);


//        if (time <= chatzosTime) {
//            Log.d("Before", "Chatzos");
//            percentageX = time / chatzosTime + 0.0f;
//            xPosition = percentageX * (lineImage.getWidth()/2) + 0.0f;
//        }else{
//            Log.d("After", "Chatzos");
//            percentageX = time / 24.0f - chatzosTime;
//            xPosition = (percentageX * (lineImage.getWidth()/2.0f)) + (lineImage.getWidth()/2);
//
//        }

    percentageX = time / 24f + 0.0f;

    xPosition = percentageX * 1000 + 0.0f;
    xPosition = (int) xPosition;
    Log.d("X Percentage", "" + percentageX);
    Log.d("X Position", "" + xPosition);


    return xPosition;


}


public float getYPosition(Date dateTime) {

    float time = getTime(dateTime);
    float chatzosTime = getTime(czc.getChatzos());

    float differeceInTime = chatzosTime - time; //reverse order from 0-12 (top down) if >1pm
    Log.d("Y hours: ", "" + time);

    Log.d("Y Chatzos", "" + chatzosTime);

    if (time >= chatzosTime) {
        time %= chatzosTime;
        differeceInTime = time + 0.0f;
    }

    float percentageY = differeceInTime / 12 + 0.0f;

    float yPosition = percentageY  * 1000 + 0.0f;
    yPosition = (int) yPosition;

    return yPosition;
}

0 个答案:

没有答案