How to change color of value's which I painted red ? I used setValueTextColor but it didn't work. It is still black
LineDataSet d1 = new LineDataSet(e1, entityList.get(i).getName());
d1.setValueTextColor(Color.rgb(255, 255, 83));
sets.add(d1);
LineData cd = new LineData(dateList, sets);
cd.setValueTextColor(Color.rgb(223, 83, 83));
d1.setValueTextColor(Color.rgb(255, 255, 83));
is meant for the highlighting values within the graph.
The things that are underlined are YAxis left and right, XAxis, and Legend
For each of them you need to set the text color to get the desired effect.
Now to get the reference of them you need the chart object:
YAxis yAxisRight = mChart.getAxisRight();
YAxis yAxisLeft = mChart.getAxisLeft();
XAxis xAxis = mChart.getXAxis();
Legend l = mChart.getLegend();
and set the color for each of them by calling setTextColor(int color) method.
You can find this in the official documentation as well.
Related
Is it possible to replace LimitLine with custom layout? So it looks something like this:enter image description here
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
ll1.setTextSize(10f);
ll1.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.addLimitLine(ll1);
I want to show vertical bars for 0 values as well. I have tried setting chart.getAxisLeft().setAxisMinimum(-1);. The axis gets shifted but there is no bars shown for zero value.
BarData barData = new BarData(dataSet);
barData.setValueFormatter(formatter);
barData.setDrawValues(true);
barData.setBarWidth(0.5f);
chart.setDrawGridBackground(false);
chart.setDrawBarShadow(false);
chart.setDrawBorders(false);
chart.animateY(1000);
chart.getAxisLeft().setGranularityEnabled(true);
chart.getAxisLeft().setAxisMaximum(5);
chart.getAxisLeft().setGranularity(1);
chart.getAxisRight().setEnabled(false);
chart.getAxisLeft().setAxisMinimum(-1);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.setDrawValueAboveBar(false);
chart.setRenderer(new RoundedBarChart(chart, chart.getAnimator(), chart.getViewPortHandler()));
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setAxisLineWidth(1);
xAxis.setDrawGridLines(false);
I am new to using the MPAndroid LineChart. I have a simple code and have produced a graph as shown below:
However, on this, I want to do the following:
1) To match the XAxis labels with the vertical grid lines, so that the grid lines also pass through the blue dots; AND
2) To show the XAxis value on the blue dots. By default, the YAxis values can be shown - I know how to do this; currently I have disabled this, and it is not shown in the picture below, but if I were to show enable them, then, they will be 0.0, 2.0, 4.0, 6.0 and 8.0 on the 5 blue dots. What I want is to show the XAxis values instead.
Could you please suggest a way? Many thanks.
I'm not sure. but its work for me.
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.RED);
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
For dynamic XAxis label,
xAxis.setValueFormatter(new IndexAxisValueFormatter(getAreaCount));
public ArrayList<String> getAreaCount() {
ArrayList<String> label = new ArrayList<>();
for (int i = 0; i < yourList.size(); i++)
label.add(yourList.get(i).getTopicName());
return label;
}
The value on the last point of the LineChart doesn't show even
in the mpAndroidChart example.
always value of the last point can't be seen I tried adding padding , layout_margin and setExtraOffsets ..
Screenshot
I'm using v3.0.0, and this is the LineChart Code:
lineChart.setDragEnabled(true);
lineChart.getDescription().setEnabled(false);
lineChart.animateY(2000);
lineChart.setDrawBorders(false);
lineChart.setVisibleXRange(3,7);
YAxis leftAxis=lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setEnabled(false);
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(lineChart);
XAxis xAxis = lineChart.getXAxis();
xAxis.setTextColor(Color.WHITE);
xAxis.setTextSize(13);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(false);
xAxis.setValueFormatter(xAxisFormatter);
I finally got it to work by a workaround.
Add an extra Entry for each dataSet after the last Entry and then set the setAxisMaximum for the xAxis to the last value, like this
dataset1.addEntry(new Entry(endDay+1,yValues1[i]));
dataSet2.addEntry(new Entry(endDay+1,yValues2[i]));
dataSet3.addEntry(new Entry(endDay+1,yValues3[i]));
xAxis.setAxisMaximum(endDay+0.1f);`
In the bar chart I am creating the first and last rows are consistently being cut in half (even if I add additional bars). This also causes the values above the bars to be out of place. I am inflating this within a fragment.
The axis are also only increasing by 0.9 instead of 1. To fix this do I need to implement the AxisValueFormatter interface?
Image:
Code:
.java
chart = (BarChart) view.findViewById(R.id.chart1);
// Chart settings
chart.setDrawGridBackground(false);
chart.setHighlightFullBarEnabled(true);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.setDescription("");
// Settings for X-Axis
XAxis xAxis = chart.getXAxis();
xAxis.setDrawGridLines(false);
xAxis.setEnabled(true);
xAxis.setDrawLabels(true);
xAxis.setPosition(XAxisPosition.BOTTOM);
// Settings for Y-Axis
YAxis leftAxis = chart.getAxisLeft();
YAxis rightAxis = chart.getAxisRight();
leftAxis.setAxisMinValue(0f);
rightAxis.setAxisMinValue(0f);
BARENTRY = new ArrayList<>();
BarEntryLabels = new ArrayList<String>();
BARENTRY.add(new BarEntry(2f, 1));
BARENTRY.add(new BarEntry(3f, 2));
BARENTRY.add(new BarEntry(4f, 3));
BARENTRY.add(new BarEntry(5f, 4));
BARENTRY.add(new BarEntry(6f, 5));
Bardataset = new BarDataSet(BARENTRY, "Projects");
Bardataset.setColors(ColorTemplate.COLORFUL_COLORS);
BARDATA = new BarData(Bardataset);
chart.setData(BARDATA);
chart.invalidate(); // refresh
chart.animateY(1500);
return view;
To answer your questions:
In order to properly show your bars you need to fit the bars, like this (don't ask me why it's not enabled by default):
chart.setFitBars(true)
You can find more information in the BarChart javadocs:
setFitBars(boolean enabled): Adds half of the bar width to each side of the x-axis range in order to allow the bars of the barchart to be fully displayed.
If you have a CombinedChart you could use setSpaceMin() and setSpaceMax() to add additional spacing on both ends of the axis:
XAxis xAxis = chart.getXAxis();
xAxis.setSpaceMin(barData.getBarWidth() / 2f);
xAxis.setSpaceMax(barData.getBarWidth() / 2f);
It is currently impossible to infuence the value positions rendered on the axis. Creating a ValueFormatter only changes the displayed text, not the actual position of the label.
Please use setAxisMinimum and setAxisMaximum, it will work perfectly!
After your BarData is instantiated, you just need
chart.getXAxis().setAxisMinimum(-data.getBarWidth() / 2);
chart.getXAxis().setAxisMaximum(count-data.getBarWidth() / 2);`
There is no need for setFitBars, and the count is BARENTRY size.
If the problem is with the first bar only, you can use negative values for the axis minimum:
xAxis.setAxisMinimum(-0.5f);
Like in the answer to this question here:
i just fixed it,settings the x range min, using
barChart.setFitBars(true);
barChart.setVisibleXRangeMinimum(barEntries.size());