Is their any possibility to hide all rounded items from this picture.
I have used the following code,
public void setDataList(List<HorizontalBarChartData> dataList, Resources resources) {
ArrayList<String> categories = new ArrayList<String>();
ArrayList<BarEntry> values = new ArrayList<BarEntry>();
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
BarDataSet set1;
for (int i = 0; i < dataList.size(); i++) {
categories.add(dataList.get(i).getName());
values.add(new BarEntry(dataList.get(i).getValue(), i));
}
/*set1 = new BarDataSet(values, "Income, Expense, Disposable Income");*/
set1 = new BarDataSet(values, "Category 1, Category 2, Category 3");
set1.setBarSpacePercent(35f);
set1.setColors(new int[]{resources.getColor(R.color.cyan_blue), resources.getColor(R.color.vermilion_tint), resources.getColor(R.color.sea_green)});
dataSets.add(set1);
BarData data = new BarData(categories, dataSets);
data.setValueTextSize(10f);
horizontalBarChart.setData(data);
}
Update
How to hide rounded part from this image?
Yes, is possible, just using following code:
mChart.setDescription(""); // Hide the description
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getLegend().setEnabled(false); // Hide the legend
As per this answer
mChart.getXAxis().setDrawLabels(false); will hide the entire X-Axis(as required for this question).
For positioning the X-Axis, following code works.
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
Position can be set to
BOTTOM
BOTH_SIDED
BOTTOM_INSIDE
TOP
TOP_INSIDE
This helps if you are trying to hide only the particular side axis instead of hiding the entire axis.
It appears mChart.setDescription() no longer accepts a String.
The method now accepts an instance of the Description Class like this:
mChart.setDescription(Description description)
So to modify or delete the Chart Description you may do it like below
Description description = new Description();
description.setText("");
mChart.setDescription(description);
Following code work for all chart
Legend l = mchart.getLegend();
l.setEnabled(false);.
To hide description, use this
mChart.getDescription().setEnabled(false)
Below code works for PieChart. Try to get same method for your Chart.
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.NONE);
chart=(LineChart) findViewById(R.id.Chart);
chart.getLegend().setEnabled(false); // for hiding square on below graph
Kotlin solution for MPAndroidChart:v3.1.0
chart.description.isEnabled = false // hide the description
chart.legend.isEnabled = false // hide the legend
chart.xAxis.setDrawLabels(false) // hide bottom label
chart.axisLeft.setDrawLabels(false) // hide left label
chart.axisRight.setDrawLabels(false) // hide right label
I had the problem, that the bottom xAxis Labels are cutted off when I used mChart.getLegend().setEnabled(false)
Now I use chart.getLegend().setForm(Legend.LegendForm.NONE); instead and the labels are not cutted of anymore
Related
How can i achieve this using MPAndroidChart ?
Using version : com.github.PhilJay:MPAndroidChart:v3.1.0-alpha
Adding code for Legend and piechart margin:
private void setPieChartData() {
//https://stackoverflow.com/a/50551488/1427037
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setExtraOffsets(5,5,10,5);
pieChart.setDragDecelerationFrictionCoef(0.9f);
pieChart.setDrawCenterText(false);
pieChart.setDrawHoleEnabled(false);
//pieChart.animateY(1000, Easing.EasingOption.EaseInOutCubic);
ArrayList<PieEntry> yValues = new ArrayList<>();
yValues.add(new PieEntry(34f,"Ilala"));
yValues.add(new PieEntry(56f,"Temeke"));
yValues.add(new PieEntry(66f,"Kinondoni"));
yValues.add(new PieEntry(45f,"Kigamboni"));
yValues.add(new PieEntry(45f,"Kigamboni2"));
pieChart.setDrawEntryLabels(false);
PieDataSet dataSet = new PieDataSet(yValues, "Desease Per Regions");
dataSet.setSliceSpace(0.1f);
dataSet.setDrawValues(false);
dataSet.setSelectionShift(5f);
dataSet.setColors(ColorTemplate.VORDIPLOM_COLORS);
PieData pieData = new PieData((dataSet));
pieData.setValueTextSize(10f);
pieData.setValueTextColor(Color.BLACK);
pieChart.setData(pieData);
pieChart.setDrawSliceText(false);
setLegend();
}
private void setLegend() {
Legend l = pieChart.getLegend();
l.setFormSize(10f); // set the size of the legend forms/shapes
l.setForm(Legend.LegendForm.SQUARE); // set what type of form/shape should be used
l.setYOffset(5f);
//l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); // set vertical alignment for legend
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); // set horizontal alignment for legend
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setTextSize(12f);
l.setTextColor(Color.BLACK);
//l.setXEntrySpace(5f); // set the space between the legend entries on the x-axis
l.setYEntrySpace(1f); // set the space between the legend entries on the y-axis
// set custom labels and colors
List<LegendEntry> entries = new ArrayList<>();
ArrayList<PieEntry> yValues = new ArrayList<>();
yValues.add(new PieEntry(34f,"Ilala"));
yValues.add(new PieEntry(56f,"Temeke"));
yValues.add(new PieEntry(66f,"Kinondoni"));
yValues.add(new PieEntry(45f,"Kigamboni"));
yValues.add(new PieEntry(45f,"Kigamboni2"));
for (int i = 0; i < 3; i++) {
LegendEntry entry = new LegendEntry();
entry.formColor = ColorTemplate.VORDIPLOM_COLORS[i];
entry.label = yValues.get(i).getLabel() ;
entries.add(entry);
}
l.setCustom(entries);
}
[![code result][2]][2]
How to set position of legend same as actual image i am getting problem to set its layout.please correct code and share any link for help
Please share details to resolve this problem
How to resolve this UI issue .. legend label should be on right side same as Required mock
For removing entry value & labels use method :
myPieChart.setDrawSliceText(false); // To remove slice text
myPieChart.setDrawMarkers(false); // To remove markers when click
myPieChart.setDrawEntryLabels(false); // To remove labels from piece of pie
myPieChart.getDescription().setEnabled(false); // To remove description of pie
For showing legends beside your chart try below methods :
Legend l = myPieChart.getLegend(); // get legend of pie
l.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER); // set vertical alignment for legend
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); // set horizontal alignment for legend
l.setOrientation(Legend.LegendOrientation.VERTICAL); // set orientation for legend
l.setDrawInside(false); // set if legend should be drawn inside or not
Check out more from here & from main doc page of MPAndroidChart.
I hope it will help!
I did it,
pieChart.setDrawCenterText(true);
pieChart.setDrawEntryLabels(true);
pieChart.setDrawMarkers(false);
pieChart.getDescription().setEnabled(false);
pieChart.getLegend().setEnabled(false);
just change to false all and you shouldn't see any text(s)!
[ sorry if i had poor English ]
I want to draw stock's history price chart with volume, similar to this:
With MPAndroidChart, I managed to get this result using CombinedChart:
Here's my code snippet:
CombinedChart mChart = (CombinedChart) findViewById(R.id.chart);
final ArrayList<BarEntry> barList = new ArrayList<>();
final ArrayList<Entry> lineList = new ArrayList<>();
// add Bar & Line data entries
.....
// bar depends on LEFT y-axis
BarDataSet barSet = new BarDataSet(barList, "");
barSet.setAxisDependency(YAxis.AxisDependency.LEFT);
BarData barData = new BarData(barSet);
// line depends on RIGHT y-axis
LineDataSet lineSet = new LineDataSet(lineList, "");
lineSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
LineData lineData = new LineData(lineSet);
// set data to chart
....
float barYMax = barData.getYMax();
float lineYMin = lineData.getYMin();
// to make bar appears at bottom
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setAxisMaximum(barYMax * 10);
// to make line appears at top
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setAxisMinimum(lineYMin * 0.5f);
In order to make "Line Chart" appears above "Bar Chart":
Bar chart depends on Left y-axis. To make bar appears at bottom, I make it's scale larger, with leftAxis.setAxisMaximum(barYMax * 10).
Line chart depends on Right y-axis. To shift line up, I do rightAxis.setAxisMinimum(lineYMin * 0.5f).
I wonder is there a better recommended way to achieve this effect?
With my solution, line chart may still overlap with bar partially. Ideally I wish to achieve no overlapping at all, with line appears completely on top of bar.
I am using MPAndroidChart.
How to change the BarEntryLabels in to left in HorizontalBarChart?vHow to remove that projects from its bottom?
How to disable zoom ?
While clicking on to particular bar colour is changing how to disable it?
IN BarChart there i have added 6 months but EntryLabels is not properly aligned to corresponding bar.
Code:
BARENTRY = new ArrayList<>();
BarEntryLabels = new ArrayList<String>();
AddValuesToBARENTRY();
AddValuesToBarEntryLabels();
Bardataset = new BarDataSet(BARENTRY, "Projects");
BARDATA = new BarData(BarEntryLabels, Bardataset);
Bardataset.setColors(new int[]{Color.parseColor("#701112")});
horizontalBarChart.setData(BARDATA);
horizontalBarChart.setDrawBarShadow(false);
horizontalBarChart.setDrawValueAboveBar(true);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
horizontalBarChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
horizontalBarChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
horizontalBarChart.setDrawGridBackground(false);
horizontalBarChart.setDescription("");
Bardataset.setBarSpacePercent(10f);
barChart.setData(BARDATA);
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(true);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
barChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
barChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
barChart.setDrawGridBackground(false);
barChart.setDescription("");
For the "project" legend part try this
Legend legend = mBarChart.getLegend();
legend.setEnabled(false);
To make touch disable set setTouchEnabled(boolean enabled) on your bar chart object like this
mBarChart.setTouchEnabled(false);
and if you want to show all label you should try
axis.setLabelCount(...)
mBarChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
and also try official documents
BARENTRY1 = new ArrayList<>();
BarEntryLabels1 = new ArrayList<String>();
AddValuesToHorizontalBARENTRY();
AddValuesToHorizontalBarEntryLabels();
Bardataset = new BarDataSet(BARENTRY1, "Projects");
BARDATA = new BarData(BarEntryLabels1, Bardataset);
Bardataset.setColors(new int[]{Color.parseColor("#701112")});
horizontalBarChart.setData(BARDATA);
horizontalBarChart.setDrawBarShadow(false);
horizontalBarChart.setDrawValueAboveBar(true);
horizontalBarChart.setPinchZoom(false);
horizontalBarChart.setDrawGridBackground(false);
horizontalBarChart.setDescription("");
Bardataset.setBarSpacePercent(10f);
Legend legend = horizontalBarChart.getLegend();
legend.setEnabled(false);
horizontalBarChart.setTouchEnabled(false);
XAxis xAxis1 = horizontalBarChart.getXAxis();
xAxis1.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis1.setTextSize(8);
xAxis1.setSpaceBetweenLabels(8);
xAxis1.setTextColor(Color.parseColor("#701112"));
xAxis1.setTypeface(tf);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setEnabled(false);
Do like this.The following issue will be fix.
I am using MPAndroidChart, this is the chart I need to create:
Hi everyone. Please help me. I'm trying to customize this chart but I can't make it come be better. have some problems:
How to add new axis at bottom chart?
How to hide horizontal lines?
List<String> xAxisValues; // YOUR DATA HERE
...
IAxisValueFormatter xAxisFormatter = new IAxisValueFormatter() {
#Override
public String getFormattedValue(float value, AxisBase axis) {
return xAxisValues.get((int) value);
}
};
...
XAxis xAxis = chart.getXAxis();
xAxis.setTextColor(Color.BLUE));
xAxis.setValueFormatter(xAxisFormatter);
I beleive the above line will match your need, below stuff will be useful may be,
LineDataSet set1 = new LineDataSet(values, title);
set1.setColor(Color.RED); // Your line color
set1.addColor(Color.GRAY); // Your Blue
set1.setCircleColor(Color.BLUE);
set1.setLineWidth(3f); // Increase here for line width
set1.setCircleRadius(10f);
set1.setDrawCircleHole(true);
set1.setValueTextSize(9f);
set1.setDrawFilled(true);
set1.setFormLineWidth(10f);
set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
set1.setFormSize(15.f);
Fine tune according to your need in above code see comments
The below two lines are important for the smooth line and filled color
set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set1.setFillColor(Color.BLUE); // Change your color
For the horizontal issue, please refere to this page
Here, I think it will be :
YourObjettoDrawVariable.getAxisRight().setDrawLabels(false);
But, it is always better to show your code for ccontext purpose.
I hope it's help.
I'm using MPChartlib for a basic "Barchart" (3 bars and values between 0 and 100).
the background of the app is dark so I'd like to put the text in white but when I set the text with color code "FFFFFF" in chart_color stored in string.xml but the text appear in dark blue.
//Axe X
XAxis x = barchart.getXAxis();
x.setPosition(XAxisPosition.BOTTOM);
x.setTextColor(R.color.chart_color);
x.setAxisLineColor(R.color.chart_color);
// Design
barchart.setDragEnabled(false);
barchart.setDrawGridBackground(false);
barchart.setTouchEnabled(false);
barchart.setHighlightEnabled(false);
barchart.setMaxVisibleValueCount(101);
barchart.setDescription(null);
barchart.setGridBackgroundColor(R.color.chart_color);
barchart.invalidate(); // refresh
//Axe Y
barchart.getAxisLeft().setAxisMaxValue(100);
barchart.getAxisLeft().setDrawTopYLabelEntry(true);
barchart.getAxisLeft().setDrawAxisLine(false);
barchart.getAxisLeft().setDrawGridLines(false);
barchart.getAxisLeft().setAxisLineColor(R.color.chart_color);
barchart.getAxisLeft().setTextColor(R.color.chart_color);
barchart.getAxisRight().setAxisMaxValue(100);
barchart.getAxisRight().setDrawTopYLabelEntry(true);
barchart.getAxisRight().setAxisLineColor(R.color.chart_color);
barchart.getAxisRight().setTextColor(R.color.chart_color);
I tried lots of things and research but couldn't find the issue, does the lib doesn't use the same kind of color code or something ?
Thanks for your help,
Alex
You are passing the resource id to the library, not the actual color.
Use this to get the color:
int color = ContextCompat.getColor(context, R.color.chart_color);
LineDataSet dataSet = ...;
dataSet.setColor(color);
You can also find this in the documentation.
if you want change bars color prefer pass context as well like example below
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(87f, 0));
entries.add(new BarEntry(90f, 1));
ArrayList<String> labels = new ArrayList<>();
labels.add("title 1");
labels.add("title 2);
BarDataSet dataSet = new BarDataSet(entries, "# of Calls ");
BarData barData = new BarData(labels, dataSet);
dataSet.setColors(new int[]{R.color.color1 , R.color.color2} , context);
barChart.setData(barData);
barChart.animateY(3000 , Easing.EasingOption.EaseOutBack );