jjoe64 / graphview-demos Goto Github PK
View Code? Open in Web Editor NEWExamples for my Android GraphView library
Home Page: http://www.jjoe64.com/p/graphview-library.html
License: MIT License
Examples for my Android GraphView library
Home Page: http://www.jjoe64.com/p/graphview-library.html
License: MIT License
I want to mark the intersection of multiple series in Line graph? Can some one provide a sample to achieve it?
it dosent seem to scale according to my values.
Hi everyone!
While using this library(thanks for it!) I stuck when I need to reset data on my GraphView
.
I store my data as LineGraphSeries
object, independent from activity lifecycle, so when activity created, or resumed I need to refresh data in another LineGraphSeries
object which is associated with GraphView
.
I check source code of BaseSeries
class and found method resetData(E[] data)
, but it take as input only array of data and it is very hard to get those array, because in BaseSeries
class there is only one method to getting data: getValues()
and it returns Iterator<E>
.
So to get array I need go through this iterator and write values to ArrayList
first(because Iterator can't tell us how much elements it has), and finally I can create array and write to it values from ArrayList
.
I think it's very long and not effective, so I suggest with minimum changes:
BaseSeries
class, which will return [] E
- array of data valuesAnd to increase usability in this reseting data case:
BaseSeries
, LineGraphSeries
, BarGraphSeries
, PointsGraphSeries
which will take as argument ArrayList <E>
BaseSeries
class, which will return ArrayList<E>
So what do think about my suggestion?
I have a personal implementation of a multicolored graph (the line and filled graph), and it would be nice to add here, but i've then switched to code similar to official android guide on graphs (navigable one),
do you want me to pull some code about it or you already have some ideas?
In BarGraphFragment call by error FullscreenExample.ADVANCED_LINE_GRAPH instead of FullscreenExample.ADVANCED_BAR_GRAPH
new AdvancedBarGraph().initGraph(graph);
rootView.findViewById(R.id.cardAdvancedBarGraph).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openFullscreen(FullscreenExample.ADVANCED_BAR_GRAPH);
}
});
rootView.findViewById(R.id.imgFullscreen2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openFullscreen(FullscreenExample.ADVANCED_LINE_GRAPH);
}
});
rootView.findViewById(R.id.imgSource2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openSource(FullscreenExample.ADVANCED_LINE_GRAPH);
When I put static labels only in the y-axis, happens this:
Well, I just want the date, and what seems to happen is that it puts the two values on the same axis (x-axis). Here's my code:
`
class MainActivity : AppCompatActivity() {
private var mNumLabels: Int = 4
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val graph = findViewById<GraphView>(R.id.graph)
initGraph(graph)
}
fun initGraph(graph: GraphView) {
// generate Dates
val calendar = Calendar.getInstance()
val d1 = calendar.time
calendar.add(Calendar.DATE, 1)
val d2 = calendar.time
calendar.add(Calendar.DATE, 1)
val d3 = calendar.time
// you can directly pass Date objects to DataPoint-Constructor
// this will convert the Date to double via Date#getTime()
val series = LineGraphSeries(arrayOf<DataPoint>(DataPoint(d1, 2.0), DataPoint(d2, 5.0), DataPoint(d3, 3.0)))
graph.addSeries(series)
series.isDrawDataPoints = true
series.isDrawBackground = true
// set date label formatter
graph.gridLabelRenderer.labelFormatter = DateAsXAxisLabelFormatter(graph.context)
graph.gridLabelRenderer.numHorizontalLabels = mNumLabels
// second series
val series2 = LineGraphSeries(
arrayOf(
DataPoint(d1, 3.0),
DataPoint(d2, 3.0),
DataPoint(d3, 6.0)
)
)
series2.title = "speed"
series2.isDrawBackground = true
series2.color = Color.argb(255, 255, 60, 60)
series2.backgroundColor = Color.argb(100, 204, 119, 119)
series2.isDrawDataPoints = true
graph.addSeries(series2)
// second series
val series3 = LineGraphSeries(
arrayOf(
DataPoint(d1, 3.0),
DataPoint(d3, 2.0)
)
)
series2.title = "HEY"
series2.isDrawBackground = true
series2.color = Color.argb(255, 255, 60, 60)
series2.backgroundColor = Color.argb(100, 204, 119, 119)
series2.isDrawDataPoints = true
graph.addSeries(series3)
// legend
graph.legendRenderer.isVisible = true
graph.legendRenderer.align = LegendRenderer.LegendAlign.BOTTOM
// set manual x bounds to have nice steps
graph.viewport.setMinX(d1.time.toDouble())
graph.viewport.setMaxX(d3.time.toDouble())
graph.viewport.isXAxisBoundsManual = false
graph.gridLabelRenderer.setHumanRounding(false)
val staticLabelsFormatter = StaticLabelsFormatter(graph)
staticLabelsFormatter.setVerticalLabels(arrayOf("low", "hey", "high", "wei", "wai"))
graph.gridLabelRenderer.labelFormatter = staticLabelsFormatter
}
}
`
When I take this: val staticLabelsFormatter = StaticLabelsFormatter(graph) staticLabelsFormatter.setVerticalLabels(arrayOf("low", "hey", "high", "wei", "wai")) graph.gridLabelRenderer.labelFormatter = staticLabelsFormatter
Everything works fine... but then I can't use static labels. Can you help me?
Hello there,
After opening a new empty android studio project and typing compile 'com.jjoe64:graphview:4.2.1'
into the app's build.gradle file, I get this error. It is also appearing on android studio of a colleague of mine:
Program type already present: android.support.v4.app.FragmentTransitionCompat21$1
Any idea what's going on?
Thanks a lot before hand, excited to get started with GraphView! :)
getting illegal argument exception on final GraphViewSeries exampleSeries3 = new GraphViewSeries("Leaves",Color.BLUE,new GraphViewData[] {
I used the example code of RealtimeGraph at https://github.com/jjoe64/GraphView-Demos/blob/master/graphviewdemos/src/main/java/com/jjoe64/graphviewdemos/RealtimeGraph.java
Whenever the screen orientation is changed, the graph is restarted again and all the previous data is not displayed.
How do i stop restarting the graph every time the screen orientation is changed?
"diagramms" instead of "diagrams"
Had a bit of a look and im fairly certain this doesn't exist yet.
graphview.getGraphAsBitmap
graphview.getAllSeriesData
as examples
How to set x axis to be date and automatically change by scrolling? thanks
Hi, their support date redundance based on picture I attach and below following code that i follow
` DateFormat fmt1 = new SimpleDateFormat("MMMM dd, yyyy", Locale.US);
Date d1 = null,d2 = null,d3 = null,d4 = null,d5 = null,d6 = null,d7 = null,
d8 = null,d9 = null,d10 = null,d11 = null, d12 = null;
try {
d1 = fmt1.parse("January 1, 2018");
d2 = fmt1.parse("February 1, 2018");
d3 = fmt1.parse("March 1, 2018");
d4 = fmt1.parse("April 1, 2018");
d5 = fmt1.parse("May 1, 2018");
d6 = fmt1.parse("June 1, 2018");
d7 = fmt1.parse("July 1, 2018");
d8 = fmt1.parse("August 1, 2018");
d9 = fmt1.parse("September 1, 2018");
d10 = fmt1.parse("October 1, 2018");
d11 = fmt1.parse("November 1, 2018");
d12 = fmt1.parse("December 1, 2018");
} catch (ParseException e) {
e.printStackTrace();
}
graphView = (GraphView)v.findViewById(R.id.graph);
series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(d1, 0),
new DataPoint(d2, 123.00),
new DataPoint(d3, 200.00),
new DataPoint(d4, 145.00),
new DataPoint(d5, 150.00),
new DataPoint(d6, 180.00),
new DataPoint(d7, 0.00),
new DataPoint(d8, 0.00),
new DataPoint(d9, 0.00),
new DataPoint(d10, 0.00),
new DataPoint(d11, 30.00),
new DataPoint(d12, 0.00)
});
series.setColor(ContextCompat.getColor(getActivity(), R.color.bgwhite));
//series.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.bgwhite));
graphView.addSeries(series);
// set date label formatter
DateFormat fmt = new SimpleDateFormat("MMM", Locale.US);
graphView.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity(), fmt));
graphView.getGridLabelRenderer().setNumHorizontalLabels(12); // only 4 because of the space
graphView.getGridLabelRenderer().setTextSize(20f);
graphView.getGridLabelRenderer().setLabelHorizontalHeight(10);
// set manual x bounds to have nice steps
graphView.getViewport().setMinX(d1.getTime());
graphView.getViewport().setMaxX(d12.getTime());
graphView.getViewport().setXAxisBoundsManual(true);
//graphView.getViewport().calcCompleteRange();
// as we use dates as labels, the human rounding to nice readable numbers
// is not necessary
graphView.getGridLabelRenderer().setHumanRounding(false); // show line graph y
`
tried samples on Nexus7, compiled with Android 4.2.2 and it seems that Realtime Graph sample doesn't correctly do scrollToEnd=true within GrahViewSeries.appendData method.
From video you can se that Y labels actually updates but linechart stays same.
I created video but only images are allowed :) - I can send it to you by email.
This isn't so much an issue but a question about using GraphView inside a fragment activity. I am getting an error Cannot resolve constructor LineGraphView
GraphView graphView;
graphView = new LineGraphView(this, message);
graphView.addSeries(exampleSeries); // data
I posted on stackoverflow and then realized I should ask here
http://stackoverflow.com/questions/21326875/android-cannot-resolve-constructor-lineviewgraph
This was done on a clean checkout of the repository
./gradlew tasks
FAILURE: Build failed with an exception.
* Where:
Build file '/home/ron/src/GraphView-Demos/graphviewdemos/build.gradle' line: 16
* What went wrong:
A problem occurred evaluating project ':graphviewdemos'.
> Ambiguous method overloading for method java.io.File#<init>.
Cannot resolve which method to invoke for [null, class java.lang.String] due to overlapping prototypes between:
[class java.lang.String, class java.lang.String]
[class java.io.File, class java.lang.String]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.235 secs
If you set graph.getViewport().setXAxisBoundsManual(true); for both the X and Y axes but then only supply a minimum for both (0 for each), the X axis will increase automatically with data while the Y axis is initiated at 1 on the graph and will not move. How do you get around this? In an older version of the code I'm running, this bug didn't happen.
Note: the data I have is coming in VIA bluetooth and being appended to a series in real time, so I cannot set a maximum value to begin with.
Is it true that the graphs do not display in classes that extent the SherlockFragmentActivity? If i extend to Activity it works but would like the support for SherlockFragmentActivity as well.
Hey joe, i am trying to create real time graph . The data on graph will come from bluetooth , it's a massive amount of data and very fast rate lets say 1sec =60 samples of data
problem is when i used appendata to add the data and fixed max data points to 400 ,it crashes after some time . i debug it , it causes memory leakage
final String[] arr = str.replace("[", "").replace("]", "").split(",");
for (int i = 0; i < arr.length; i++) {
mSeries.appendData(new DataPoint(graph2LastXValue, Double.parseDouble(arr[i])),true,380);
//DataPoint v = new DataPoint(graph2LastXValue,Double.parseDouble(arr[i]));
// myArr[i]=v;
// mSeries2.appendData(myArr[i], true, 380);
graph2LastXValue++;}
Hi,
you've made the GraphView-Lib as a Git-Submodule. Would be nice to mention that in your readme cause git doesn't clone submodule automatically.
In examples you use that method (setLegendSpacing). It doesn't exists anywhere.
Hi everyone
I'm very pleased with the library, great works!
Problem is, I don't understand why it behaves inconsistently, meaning that one time it shows like this (without date X labels and incorrect Y axis rounding)
in place of the correct display
I'm following the example Dates.java
https://github.com/jjoe64/GraphView-Demos/blob/master/app/src/main/java/com/jjoe64/graphview_demos/examples/Dates.java
if (story.getId().equals(storyId)) {
GraphView graph = (GraphView) findViewById(R.id.graph);
DataPoint[] dataPoints = new DataPoint[story.getMetrics().size()];
int i = 0;
for (Story.Metric metric : story.getMetrics()) {
dataPoints[i] = new DataPoint(metric.getDate(), (int)metric.getConversations());
i++;
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(dataPoints);
series.setAnimated(true);
graph.addSeries(series);
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(graph.getContext(), new SimpleDateFormat(LABEL_DATE_FORMAT)));
graph.getGridLabelRenderer().setNumHorizontalLabels(dataPoints.length);
// as we use dates as labels, the human rounding to nice readable numbers
// is not nessecary
graph.getGridLabelRenderer().setHumanRounding(false);
// set manual x bounds to have nice steps
graph.getViewport().setMinX(story.getMetrics().get(0).getDate().getTime());
graph.getViewport().setMaxX(story.getMetrics().get(story.getMetrics().size() - 1).getDate().getTime());
graph.getViewport().setXAxisBoundsManual(true);
}
I'm really puzzled..
thanks
nicola
I have an activity that holds 2 fragments with a viewpager to scroll between them. In the first fragment i have an mapfragment and a graphview which is scalable. In the second one, i have some basic stuff like textviews and such. Now, if i want to browse in my graphview, i scroll a little bit and then the viewpager takes over and takes me to the other fragment. Is there a way on how i can fix this?
Hi,
I need to create a custom graph according to my need.
Actually, i am updating the graph based on sound by recording audio. I got the result in byte array.
But i am unable to assign byte array to graph. :( As, graph object doesn't have any method to show the byte array. It just have method to addSeries. i.e. Object of DataPoints which have 2 double values.
I need to pass a byte array and need to update the graph accordingly.
For that i need to customize the java classes of the library but it's not allowing me as it is in jar.
Please help, or if you have some other solution w.r.t. this then please do reply..
Thank you in advance.
I need to create the graph like this,
Good morning
I am just interesting about future of GraphView
Is any chance to see the additional development of
pie chart
polar chart
radar chart?
GraphViewSeries is missing from GraphView-2.5.jar
I want to add the Months name on the Xaxis of the Chart how to do it , I can see any thing to achieve this , Following is the method which makes the index on the xAxis
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});
So how can I set the months name on the XAxis
Hello Team,
Please give any way to break line graph when we are updating multiple series with respect of time. if we are unable to find value in any series than i want to show break then when value not available.
if you scale out you will see x lables that doesn't have data , even in you demo if you try to scale out you will se the bug .
With ADT (version 21.0.0.v201210310015-519525)
The library is correctly used for autocompletion, but is not used at run time, resulting in a java.lang.NoClassDefFoundError !
Correction:
Move jar from lib ditectory to libs one (with a "S")
See answer :
http://stackoverflow.com/a/9916751
i m using eclipse have made prj in eclipse and have added jar file as lib but still i m getting error GraphViewSeries in this class when trying to use this code
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.