MPAndroidChart: chart only displaying during animation - android

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.

Related

Remove "No chart data available" from MPAndroidChart and add my own message

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.

How to hide value labels in MPAndroidChart

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);

Telerik LineSeries DataPoint Circle

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

Can Y Axis on GraphView in eclipse be set to 2 decimal places

GraphViewData[] data = new GraphViewData[numElements];
for (int c = 0; c<numElements; c++) {
data[c] = new GraphViewData(c+1, pvalueArray[c]);
}
GraphView graphView = new LineGraphView(this, Captionname);
GraphViewSeries graphViewSeries = new GraphViewSeries(data);
I am populating a graph as above, my array contains values set to 2 decimal places.
When I use the graph on my app, the Y axis goes up to 3 decimal places. Can I force it to be 2?
I am using version 3.1.3. I don't really want to upgrade and have to change loads of code.
How do I use DefaultLabelFormatter? - Sorry I can't add a comment as I'm new!
I have had to upgrade to version 4 then I can use
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(1);
nf.setMinimumIntegerDigits(2);
graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter(nf, nf));
Now stuck on how to add data from my array!!!

Android Graphview changing x axis data

in my app I'm using GraphView library to create a LineGraphView. It shows data from specified dates from example from 18.01 to 30.01. When I change the boundaries for example from 25.01 to 29.01 GraphView updates the chart (cuts not needed lines) but still shows wrong x axis data (18.01 to 30.01), however when user starts to interact with chart (zooming, scrolling) it updates it's x axis and everything is fine. Is there a method to force GraphView to update it's x axis? I have only encountered this problem if user has been interacting with chart (zooming, scrolling) before changing dates if there was no interaction graphview updates properly. I'm creating charts this way:
Inside onCreate:
mGraphView = new LineGraphView(this, "Temperature Measurements");
And a function to create a chart when I fetch data from database:
public void createChart(Cursor cursor) {
GraphViewData[] values = new GraphViewData[cursor.getCount()];
while (cursor.moveToNext()) {
String time = cursor.getString(cursor
.getColumnIndex(MeasurementEntry.DATE_IN_MINUTES));
String temp = cursor.getString(cursor
.getColumnIndex(MeasurementEntry.TEMPERATURE));
values[cursor.getPosition()] = new GraphViewData(
Double.parseDouble(time), Double.parseDouble(temp));
}
mGraphView.removeAllSeries();
mGraphView.addSeries(new GraphViewSeries(values));
mGraphView.setScalable(true);
mGraphView.getGraphViewStyle().setTextSize(15);
final SimpleDateFormat formatter = new SimpleDateFormat(
"dd.MM.yyyy HH:mm");
mGraphView.setCustomLabelFormatter(new CustomLabelFormatter() {
#Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
return formatter.format(new Date((long) value));
}
return null;
}
});
}
And here is the screenshot with the problem:
OK, so I made it however I think it can be done better, what I done is removing graphView from parent layout, creating new graphview and adding new graphview - I do this sequence everytime user is changing the boundaries. Maybe it will help somebody (short snippet of createChart method, container is my parent layout):
container.removeView(mGraphView);
mGraphView = new LineGraphView(this, "Temperature Measurements");
container.addView(mGraphView);
mGraphView.removeAllSeries();
mGraphView.addSeries(new GraphViewSeries(values));
mGraphView.setScalable(true);
mGraphView.getGraphViewStyle().setTextSize(15);

Categories

Resources