I am using MPAndroidChart Library for showing a Bar Chart. Empty view for Data Bar Chart is showing "No chart data available":
Also I need to change this message. But it's not working for changing this I have used this code lines:
mChart.setNoDataText("No chart");
mChart.invalidate();
pieChart.setNoDataText();
use it and u will get your desired Text
also if you want some descriptive text then you can use
pieChart.setNoDataTextDescription();
First you can use:
chart.setNoDataText("Your description");
Then, you can customize through Paint object:
mChart.setNoDataText("Description that you want");
Paint p = mChart.getPaint(Chart.PAINT_INFO);
p.setTextSize(...);
p.setColor(...);
p.setTypeface(...);
Font: MPAndroidChart - Change message "No chart data available"
Have you added LineDataSet?
LineData xData = mChart.getData();
ILineDataSet x = xData.getDataSetByIndex(0);
x = createXSet();
xData.addDataSet(x);
xData.addEntry(new Entry(5f, 21, 0);
xData.notifyDataChanged();
mChart.notifyDataSetChanged();
mChart.setVisibleXRangeMaximum(30);
mChart.moveViewToX(xData.getEntryCount());
private LineDataSet createXSet(boolean drawPoints) {
LineDataSet set = new LineDataSet(null, "x");
set.setColor(Color.GREEN);
set.setLineWidth(2f);
set.setCircleRadius(2f);
set.setCircleColor(Color.WHITE);
set.setFillAlpha(65);
set.setFillColor(Color.GREEN);
set.setHighLightColor(Color.rgb(244, 117, 117));
set.setValueTextColor(Color.WHITE);
set.setValueTextSize(9f);
set.setDrawValues(false);
return set;
}
Make chart invisible until data is populated. This should solve the problem.
Related
Below is my simple code for a line chart. If I use this code but only have one Entry, one point shows on the graph, which is good. If I add any more, like I have below, nothing at all shows, unless I add "newchart.animateX(3000);, in which case the chart shows for 3000ms and then disappears.... what gives?
LineChart newchart = (LineChart) findViewById(R.id.chart);
ArrayList<Entry> YAxis = new ArrayList<>();
Entry startingtemp = new Entry(0,3);
Entry next = new Entry(1,6);
YAxis.add(next);
YAxis.add(startingtemp);
LineDataSet temps = new LineDataSet(YAxis, "fuck");
ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(temps);
LineData data = new LineData(dataSets);
newchart.setData(data);
newchart.animateX(3000);
newchart.invalidate();
Okay, the reason it wasn't working was because I added an x value of 1 before 0. when i switched the order in which i added the two entrys to the array, it started working fine.
How to remove the label in aBarChart. I have attached screenshot with what I want to remove marked in red. How do I remove that number?
Here is screenshot:
BarDataSet dataset = new BarDataSet(entries, "");
BarData data = new BarData(labels, dataset);
barChart.setData(data);
you need to add below line to hide label
dataSet.setDrawValues(false);
I have a LineSeries
RadCartesianChartView chart = new RadCartesianChartView(context);
CartesianChartGrid cartesianChartGrid = new CartesianChartGrid();
cartesianChartGrid.setMajorYLinesRenderMode(GridLineRenderMode.INNER_AND_LAST);
cartesianChartGrid.setMajorXLinesRenderMode(GridLineRenderMode.INNER_AND_LAST);
cartesianChartGrid.setLineThickness(1);
cartesianChartGrid.setLineColor(Color.CYAN);
chart.setGrid(cartesianChartGrid);
LineSeries series = new LineSeries();
series.setStrokeColor(Color.GRAY);
But line is shown continuous without any point denoting the data point.
How can I show circles as data points on line.
To show the data points you have to add some methods in series.
series.setShowLabels(true);
And in case you need you can format labels in any java format you need
series.setLabelFormat("%.0f");
Hope it helps
I am using jjoe64 Graph View in my android application.
and I am trying to show dynamic values in graph but first time it contains no values but graph is not appearing.
give me solution.
http://www.android-graphview.org/
https://github.com/jjoe64/GraphView
Can you show us your code?
Have you tried something like
graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>();
graph.addSeries(series);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(0);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(4);
graph.onDataChanged(true, true);
There's a bug report logged for this one, and it appears the issue will be fixed in the next release (4.0.1).Anyway I simply coded around the issue, by displaying some text, indicating there's no data at that point eg.
// If there is no data, let the user know, else blank the textBox.
TextView fragmentText = (TextView) v.findViewById(R.id.history_text);
if ( xLabels.size() < 2 ){
fragmentText.setTextSize(24);
fragmentText.setText(getString(R.string.history_graph_no_data));
} else {
// Remove the "No Data" text
fragmentText.setText("");
LinearLayout layout = (LinearLayout) v.findViewById(R.id.history_graph);
addGraphToLayout(layout);
}
Basically i want to draw a graph where x-axis gives you the date and y axis gives u the count
I am getting data from server and parsing it in my two array's one is for count and other is for date
i am getting values in two array like this
SoapObject o=(SoapObject)p2.getProperty(xx);
UserCallStatusBean ld=new UserCallStatusBean();
if(o.getProperty("Month").toString().equals("anyType{}")){
ld.setDuration("");
}
else{
ld.setDuration(o.getProperty("Month").toString());
}
ld.setCount(Integer.parseInt(o.getProperty("Count").toString()));
CallStatus.add(ld);
GraphViewData o1=new GraphViewData(_iLoopCounter,Double.parseDouble(o.getProperty("Count").toString()));
String o2=new String(o.getProperty("Month").toString());
//String o2=new String(String.valueOf(_iLoopCounter));
arrData[xx]=o1;
arrXaxis[xx]=o2;
_iLoopCounter++;
After Getting the Value in two array i use Graph View Demo to create a grapg like
setContentView(R.layout.graphs);
// init example series data
exampleSeries = new GraphViewSeries(arrData);
// graph with dynamically genereated horizontal and vertical labels
GraphView graphView;
graphView = new BarGraphView(
this,"");
graphView.addSeries(exampleSeries); // data
graphView.setScalable(true);
graphView.setScrollable(true);
graphView.setViewPort(2,6);
graphView.setScrollable(true);
graphView.setHorizontalLabels(arrXaxis);
graphView.setGravity(Gravity.CENTER);
graphView.setBaselineAlignedChildIndex(4);
//graphView.setHorizontalLabels(labels);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
Now My issue of concern is i am getting value of count on y-axis but i am also getting count of date on x-axis instead i want to show the date on x-axis
I Have read various articles to get string value on x-axis ,finded one to use Cutom lavel formatter , But didnt knw how to use so what i can do to get x-axis ? (Date Value)
I hope u understands ,Expecting Answer Pleasue will b aLl Mine
Thanks in advance