(MPAndroidChart-LineChart) I didn't get the last label in my app
I use MPAndroidChart v3.0.2 now.
The problem is that lasst data('05일') is not showing...
This is the value while I get on Debug
xVals : 1일, 2일, 5일
and It is the source and the result screenshot.
I think the '5일' enter the 'red circle'... but I don't know the reason..
LineChart chart = (LineChart) findViewById(R.id.chart);
if (ExRegList.length() == 0) {
chart.clear();
chart.setDescription(null);
chart.setNoDataText("데이터가 존재하지 않습니다."); // There is no data.
chart.invalidate();
} else {
ArrayList<Entry> entries = new ArrayList<Entry>();
final String xVals = new String[ExRegList.length()];
try {
for (int i = 0; i < ExRegList.length(); i++) {
JSONObject obj = ExRegList.getJSONObject(i);
String date = obj.getString("REG_DT").split("-")[2] + "일";
xVals[i] = date;
int score = obj.getInt("ANSWER02");
switch (score) {
case 1:
entries.add(new Entry(i,3f));//매우만족
break;
case 2:
entries.add(new Entry(i,2f));
break;
case 3:
entries.add(new Entry(i,1f));
break;
case 4:
entries.add(new Entry(i,0f));//매우불만족
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
LineDataSet lineDataSet = new LineDataSet(entries, "");
lineDataSet.setLineWidth(2);
lineDataSet.setDrawCircleHole(true);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawHorizontalHighlightIndicator(false);
lineDataSet.setDrawHighlightIndicators(false);
lineDataSet.setDrawValues(false);
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
XAxis bottomAxis = chart.getXAxis();
bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
bottomAxis.setDrawLabels(true);
bottomAxis.setDrawGridLines(false);
bottomAxis.setDrawAxisLine(true);
bottomAxis.setLabelCount(entries.size());
YAxis yAxis = chart.getAxisLeft();
yAxis.setLabelCount(4, true);
yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(3.0f);
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase yAxis) {
String format = "";
switch ((int) value) {
case 3:
format = "매우 만족";
break;
case 2:
format = "만족";
break;
case 1:
format = "불만족";
break;
case 0:
format = "매우 불만족";
break;
default:
break;
}
return format;
}
});
yAxis.setTextColor(Color.BLACK);
YAxis yRAxis = chart.getAxisRight();
yRAxis.setDrawLabels(false);
yRAxis.setDrawAxisLine(false);
yRAxis.setDrawGridLines(false);
chart.setFocusable(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setDrawGridBackground(false);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.animateY(2000, Easing.EasingOption.EaseInCubic);
chart.invalidate();
android mpandroidchart linechart
add a comment |
I use MPAndroidChart v3.0.2 now.
The problem is that lasst data('05일') is not showing...
This is the value while I get on Debug
xVals : 1일, 2일, 5일
and It is the source and the result screenshot.
I think the '5일' enter the 'red circle'... but I don't know the reason..
LineChart chart = (LineChart) findViewById(R.id.chart);
if (ExRegList.length() == 0) {
chart.clear();
chart.setDescription(null);
chart.setNoDataText("데이터가 존재하지 않습니다."); // There is no data.
chart.invalidate();
} else {
ArrayList<Entry> entries = new ArrayList<Entry>();
final String xVals = new String[ExRegList.length()];
try {
for (int i = 0; i < ExRegList.length(); i++) {
JSONObject obj = ExRegList.getJSONObject(i);
String date = obj.getString("REG_DT").split("-")[2] + "일";
xVals[i] = date;
int score = obj.getInt("ANSWER02");
switch (score) {
case 1:
entries.add(new Entry(i,3f));//매우만족
break;
case 2:
entries.add(new Entry(i,2f));
break;
case 3:
entries.add(new Entry(i,1f));
break;
case 4:
entries.add(new Entry(i,0f));//매우불만족
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
LineDataSet lineDataSet = new LineDataSet(entries, "");
lineDataSet.setLineWidth(2);
lineDataSet.setDrawCircleHole(true);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawHorizontalHighlightIndicator(false);
lineDataSet.setDrawHighlightIndicators(false);
lineDataSet.setDrawValues(false);
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
XAxis bottomAxis = chart.getXAxis();
bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
bottomAxis.setDrawLabels(true);
bottomAxis.setDrawGridLines(false);
bottomAxis.setDrawAxisLine(true);
bottomAxis.setLabelCount(entries.size());
YAxis yAxis = chart.getAxisLeft();
yAxis.setLabelCount(4, true);
yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(3.0f);
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase yAxis) {
String format = "";
switch ((int) value) {
case 3:
format = "매우 만족";
break;
case 2:
format = "만족";
break;
case 1:
format = "불만족";
break;
case 0:
format = "매우 불만족";
break;
default:
break;
}
return format;
}
});
yAxis.setTextColor(Color.BLACK);
YAxis yRAxis = chart.getAxisRight();
yRAxis.setDrawLabels(false);
yRAxis.setDrawAxisLine(false);
yRAxis.setDrawGridLines(false);
chart.setFocusable(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setDrawGridBackground(false);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.animateY(2000, Easing.EasingOption.EaseInCubic);
chart.invalidate();
android mpandroidchart linechart
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24
add a comment |
I use MPAndroidChart v3.0.2 now.
The problem is that lasst data('05일') is not showing...
This is the value while I get on Debug
xVals : 1일, 2일, 5일
and It is the source and the result screenshot.
I think the '5일' enter the 'red circle'... but I don't know the reason..
LineChart chart = (LineChart) findViewById(R.id.chart);
if (ExRegList.length() == 0) {
chart.clear();
chart.setDescription(null);
chart.setNoDataText("데이터가 존재하지 않습니다."); // There is no data.
chart.invalidate();
} else {
ArrayList<Entry> entries = new ArrayList<Entry>();
final String xVals = new String[ExRegList.length()];
try {
for (int i = 0; i < ExRegList.length(); i++) {
JSONObject obj = ExRegList.getJSONObject(i);
String date = obj.getString("REG_DT").split("-")[2] + "일";
xVals[i] = date;
int score = obj.getInt("ANSWER02");
switch (score) {
case 1:
entries.add(new Entry(i,3f));//매우만족
break;
case 2:
entries.add(new Entry(i,2f));
break;
case 3:
entries.add(new Entry(i,1f));
break;
case 4:
entries.add(new Entry(i,0f));//매우불만족
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
LineDataSet lineDataSet = new LineDataSet(entries, "");
lineDataSet.setLineWidth(2);
lineDataSet.setDrawCircleHole(true);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawHorizontalHighlightIndicator(false);
lineDataSet.setDrawHighlightIndicators(false);
lineDataSet.setDrawValues(false);
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
XAxis bottomAxis = chart.getXAxis();
bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
bottomAxis.setDrawLabels(true);
bottomAxis.setDrawGridLines(false);
bottomAxis.setDrawAxisLine(true);
bottomAxis.setLabelCount(entries.size());
YAxis yAxis = chart.getAxisLeft();
yAxis.setLabelCount(4, true);
yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(3.0f);
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase yAxis) {
String format = "";
switch ((int) value) {
case 3:
format = "매우 만족";
break;
case 2:
format = "만족";
break;
case 1:
format = "불만족";
break;
case 0:
format = "매우 불만족";
break;
default:
break;
}
return format;
}
});
yAxis.setTextColor(Color.BLACK);
YAxis yRAxis = chart.getAxisRight();
yRAxis.setDrawLabels(false);
yRAxis.setDrawAxisLine(false);
yRAxis.setDrawGridLines(false);
chart.setFocusable(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setDrawGridBackground(false);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.animateY(2000, Easing.EasingOption.EaseInCubic);
chart.invalidate();
android mpandroidchart linechart
I use MPAndroidChart v3.0.2 now.
The problem is that lasst data('05일') is not showing...
This is the value while I get on Debug
xVals : 1일, 2일, 5일
and It is the source and the result screenshot.
I think the '5일' enter the 'red circle'... but I don't know the reason..
LineChart chart = (LineChart) findViewById(R.id.chart);
if (ExRegList.length() == 0) {
chart.clear();
chart.setDescription(null);
chart.setNoDataText("데이터가 존재하지 않습니다."); // There is no data.
chart.invalidate();
} else {
ArrayList<Entry> entries = new ArrayList<Entry>();
final String xVals = new String[ExRegList.length()];
try {
for (int i = 0; i < ExRegList.length(); i++) {
JSONObject obj = ExRegList.getJSONObject(i);
String date = obj.getString("REG_DT").split("-")[2] + "일";
xVals[i] = date;
int score = obj.getInt("ANSWER02");
switch (score) {
case 1:
entries.add(new Entry(i,3f));//매우만족
break;
case 2:
entries.add(new Entry(i,2f));
break;
case 3:
entries.add(new Entry(i,1f));
break;
case 4:
entries.add(new Entry(i,0f));//매우불만족
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
LineDataSet lineDataSet = new LineDataSet(entries, "");
lineDataSet.setLineWidth(2);
lineDataSet.setDrawCircleHole(true);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawHorizontalHighlightIndicator(false);
lineDataSet.setDrawHighlightIndicators(false);
lineDataSet.setDrawValues(false);
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
XAxis bottomAxis = chart.getXAxis();
bottomAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
bottomAxis.setDrawLabels(true);
bottomAxis.setDrawGridLines(false);
bottomAxis.setDrawAxisLine(true);
bottomAxis.setLabelCount(entries.size());
YAxis yAxis = chart.getAxisLeft();
yAxis.setLabelCount(4, true);
yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(3.0f);
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase yAxis) {
String format = "";
switch ((int) value) {
case 3:
format = "매우 만족";
break;
case 2:
format = "만족";
break;
case 1:
format = "불만족";
break;
case 0:
format = "매우 불만족";
break;
default:
break;
}
return format;
}
});
yAxis.setTextColor(Color.BLACK);
YAxis yRAxis = chart.getAxisRight();
yRAxis.setDrawLabels(false);
yRAxis.setDrawAxisLine(false);
yRAxis.setDrawGridLines(false);
chart.setFocusable(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setDrawGridBackground(false);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.animateY(2000, Easing.EasingOption.EaseInCubic);
chart.invalidate();
android mpandroidchart linechart
android mpandroidchart linechart
edited Nov 20 '18 at 17:23
Cœur
18.6k9110150
18.6k9110150
asked Jan 5 '18 at 14:38
AdrianAdrian
10811
10811
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24
add a comment |
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24
add a comment |
1 Answer
1
active
oldest
votes
Instead of this:
bottomAxis.setLabelCount(entries.size());
Use this overloaded version:
bottomAxis.setLabelCount(entries.size(), true);
Second parameter, boolean force
forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:
sets the number of label entries for the y-axis max = 25, min = 2,
default: 6, be aware that this number is not fixed (if force == false)
and can only be approximated.
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48115765%2fmpandroidchart-linechart-i-didnt-get-the-last-label-in-my-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Instead of this:
bottomAxis.setLabelCount(entries.size());
Use this overloaded version:
bottomAxis.setLabelCount(entries.size(), true);
Second parameter, boolean force
forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:
sets the number of label entries for the y-axis max = 25, min = 2,
default: 6, be aware that this number is not fixed (if force == false)
and can only be approximated.
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
add a comment |
Instead of this:
bottomAxis.setLabelCount(entries.size());
Use this overloaded version:
bottomAxis.setLabelCount(entries.size(), true);
Second parameter, boolean force
forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:
sets the number of label entries for the y-axis max = 25, min = 2,
default: 6, be aware that this number is not fixed (if force == false)
and can only be approximated.
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
add a comment |
Instead of this:
bottomAxis.setLabelCount(entries.size());
Use this overloaded version:
bottomAxis.setLabelCount(entries.size(), true);
Second parameter, boolean force
forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:
sets the number of label entries for the y-axis max = 25, min = 2,
default: 6, be aware that this number is not fixed (if force == false)
and can only be approximated.
Instead of this:
bottomAxis.setLabelCount(entries.size());
Use this overloaded version:
bottomAxis.setLabelCount(entries.size(), true);
Second parameter, boolean force
forces to have exact number of labels. Without it, sometimes the method doesn't work, like in your case. From source code you can see:
sets the number of label entries for the y-axis max = 25, min = 2,
default: 6, be aware that this number is not fixed (if force == false)
and can only be approximated.
answered Jan 5 '18 at 15:23
Misha AkopovMisha Akopov
3,816224363
3,816224363
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
add a comment |
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
1
1
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
OMG! Thanks a lot!! Why I miss this point...I've seen about it.. Thanks!! You always save my time. Thanks!!
– Adrian
Jan 6 '18 at 13:13
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
Sir, could you see one thing..?? I read almost write about it, but I didn't resolve it...!! stackoverflow.com/questions/48142361/…
– Adrian
Jan 7 '18 at 23:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48115765%2fmpandroidchart-linechart-i-didnt-get-the-last-label-in-my-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hah, helped again :) See my answer. I've tested it and it is working now
– Misha Akopov
Jan 5 '18 at 15:24