I am using MPAndroidChart to make my combined chart. As shown at the title, I combine Scatter and Line Chart. Scatter to draw the shape and Line to connect all the Scatter. But I don't know how, my line chart is cut off
Here is what I mean about the cut off
and here is my code of Java
public class hasill1 extends AppCompatActivity {
private static final String TAG = "hasill1";
private Float pnmaks, mntar, pntar, pntek, mntek, mnsei, pnsei, mnnull;
private CombinedChart mScatter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hasill1);
mScatter = (CombinedChart) findViewById(R.id.scatter);
mScatter.getDescription().setEnabled(false);
mScatter.setBackgroundColor(Color.WHITE);
mScatter.setDrawGridBackground(false);
mScatter.setDrawBarShadow(false);
mScatter.setHighlightFullBarEnabled(false);
mScatter.setDrawOrder(new CombinedChart.DrawOrder[]{CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.BUBBLE, CombinedChart.DrawOrder.CANDLE,
CombinedChart.DrawOrder.LINE, CombinedChart.DrawOrder.SCATTER});
Legend l = mScatter.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mScatter.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis leftAxis = mScatter.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
XAxis xAxis = mScatter.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IndexAxisValueFormatter());
ArrayList<String> labels = new ArrayList<String>();
CombinedData data = new CombinedData();
data.setData(generateLineData());
data.setData(generateScatterData());
mScatter.setData(data);
mScatter.invalidate();
}
private LineData generateLineData() {
LineData c = new LineData();
ArrayList<Entry> dataSet = new ArrayList<Entry>();
Intent intent = getIntent();
float pnmaks = (float) intent.getDoubleExtra("pnmaks", 0.00);
float mntek = (float) intent.getDoubleExtra("mntek", 0.00);
float pntek = (float) intent.getDoubleExtra("pntek", 0.00);
float mnsei = (float) intent.getDoubleExtra("mnsei", 0.00);
float pnsei = (float) intent.getDoubleExtra("pnsei", 0.00);
float mntar = (float) intent.getDoubleExtra("mntar", 0.00);
float pntar = (float) intent.getDoubleExtra("pntar", 0.00);
float mnnull = (float) intent.getDoubleExtra("mnnull", 0.00);
dataSet.add(new Entry(0, pnmaks));
dataSet.add(new Entry(mntek, pntek));
dataSet.add(new Entry(mnsei, pnsei));
dataSet.add(new Entry(mntar, pntar));
dataSet.add(new Entry(mnnull, 0));
ArrayList<Entry> dataSet2 = new ArrayList<Entry>();
float pnmaksd = (float) intent.getDoubleExtra("pnmaksd", 0.00);
float mntekd = (float) intent.getDoubleExtra("mntekd", 0.00);
float pntekd = (float) intent.getDoubleExtra("pntekd", 0.00);
float mnseid = (float) intent.getDoubleExtra("mnseid", 0.00);
float pnseid = (float) intent.getDoubleExtra("pnseid", 0.00);
float mntard = (float) intent.getDoubleExtra("mntard", 0.00);
float pntard = (float) intent.getDoubleExtra("pntard", 0.00);
float mnnulld = (float) intent.getDoubleExtra("mnnulld", 0.00);
dataSet2.add(new Entry(0, pnmaksd));
dataSet2.add(new Entry(mntekd, pntekd));
dataSet2.add(new Entry(mnseid, pnseid));
dataSet2.add(new Entry(mntard, pntard));
dataSet2.add(new Entry(mnnulld, 0));
LineData d = new LineData();
LineDataSet set = new LineDataSet(dataSet, "KNL");
set.setMode(LineDataSet.Mode.LINEAR);
set.setColor(Color.RED);
set.setLineWidth(2.5f);
set.setCircleColor(Color.RED);
set.setFillColor(Color.WHITE);
set.setDrawValues(true);
set.setValueTextSize(10f);
set.setValueTextColor(Color.RED);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
LineDataSet set2 = new LineDataSet(dataSet2, "KDL");
set2.setMode(LineDataSet.Mode.LINEAR);
set2.setColor(Color.BLUE);
set2.setLineWidth(2.5f);
set2.setCircleColor(Color.BLUE);
set2.setFillColor(Color.WHITE);
set2.setDrawValues(true);
set2.setValueTextSize(10f);
set2.setValueTextColor(Color.BLUE);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
LineData n = new LineData(set,set2);
return n;
}
private ScatterData generateScatterData() {
ScatterData d = new ScatterData();
ArrayList<Entry> dataSet1 = new ArrayList<Entry>();
Intent intent = getIntent();
float pnmaks = (float) intent.getDoubleExtra("pnmaks", 0.00);
float mntek = (float) intent.getDoubleExtra("mntek", 0.00);
float pntek = (float) intent.getDoubleExtra("pntek", 0.00);
float mnsei = (float) intent.getDoubleExtra("mnsei", 0.00);
float pnsei = (float) intent.getDoubleExtra("pnsei", 0.00);
float mntar = (float) intent.getDoubleExtra("mntar", 0.00);
float pntar = (float) intent.getDoubleExtra("pntar", 0.00);
float mnnull = (float) intent.getDoubleExtra("mnnull", 0.00);
dataSet1.add(new Entry(0, pnmaks));
dataSet1.add(new Entry(mntek, pntek));
dataSet1.add(new Entry(mnsei, pnsei));
dataSet1.add(new Entry(mntar, pntar));
dataSet1.add(new Entry(mnnull, 0));
ArrayList<Entry> dataSet3 = new ArrayList<Entry>();
float pnmaksd = (float) intent.getDoubleExtra("pnmaksd", 0.00);
float mntekd = (float) intent.getDoubleExtra("mntekd", 0.00);
float pntekd = (float) intent.getDoubleExtra("pntekd", 0.00);
float mnseid = (float) intent.getDoubleExtra("mnseid", 0.00);
float pnseid = (float) intent.getDoubleExtra("pnseid", 0.00);
float mntard = (float) intent.getDoubleExtra("mntard", 0.00);
float pntard = (float) intent.getDoubleExtra("pntard", 0.00);
float mnnulld = (float) intent.getDoubleExtra("mnnulld", 0.00);
dataSet3.add(new Entry(0, pnmaksd));
dataSet3.add(new Entry(mntekd, pntekd));
dataSet3.add(new Entry(mnseid, pnseid));
dataSet3.add(new Entry(mntard, pntard));
dataSet3.add(new Entry(mnnulld, 0));
ArrayList<Entry> dataSet4 = new ArrayList<Entry>();
float Mu = (float) intent.getDoubleExtra("Mu", 0.00);
float Pu = (float) intent.getDoubleExtra("Pu", 0.00);
dataSet4.add(new Entry(Mu, Pu));
ScatterDataSet set4 = new ScatterDataSet(dataSet4, "Mu-Pu");
set4.setColors(Color.GREEN);
set4.setScatterShapeSize(7.5f);
set4.setDrawValues(true);
set4.setValueTextSize(10f);
ScatterDataSet set1 = new ScatterDataSet(dataSet1, "KNS");
set1.setColors(Color.YELLOW);
set1.setScatterShapeSize(7.5f);
set1.setDrawValues(false);
set1.setValueTextSize(10f);
ScatterDataSet set3 = new ScatterDataSet(dataSet3, "KDS");
set3.setColors(Color.BLACK);
set3.setScatterShapeSize(7.5f);
set3.setDrawValues(false);
set3.setValueTextSize(10f);
ScatterData f = new ScatterData(set1,set3,set4);
return f;
}
}
At first I make the scatter chart, and the plot go well, but when I combine it with line, it become like at the picture
Actually I don't have any programming background but I really need to finish this program cause this is my assignment. I really appreciate any help cause I have looking for a solution but I can't get it.
Thankyou anyway
question from:
https://stackoverflow.com/questions/66062621/combined-scatter-and-line-chart-using-mpandroidchart-cut-off