I need to implement a Bar chart Where it reads values when the user touches the graph to move it vertically. The graph moves up, recording the value in accordance with the axis . With x axis being the value and the Y axis being the variables , i need to perform calculations. Example to understand
Take a look at this example. You can also do mChartView.addPanListener and handle this event for what you need.
Related
Is it possible to generate a bar graph in jFreeChart where bars all start around a particular value instead of the zero axis? Our team has interest in this view.
Here is an example where the default behavior has the bars all between the value and the origin. We want the bars to be between the value and the mean (average).
I suppose a workaround is we calculate the offset from the mean and plot them in respect to the origin and then hide the axis but then we are not able to show the axis to our users.
Instead of having bar graphs stop at another value besides the origin we are just redefining the graph axis origin to be at the mean and offsetting everything. So instead of something like exposure level we now call the value axis distance from aggregate mean. Not exactly what I was originally looking in the OP but a cleaner solution overall. We'll let the user toggle between the two modes.
I'm trying to implement custom gesture logic for a CombinedChart in MPAndroidChart. Effectively, what I want to accomplish is to have a long press 'enable' highlighting of values but a short press & swipe just control panning / translating the chart (when zoomed). This would allow you to highlight values in a zoomed viewport without translating the chart (by long pressing before scrolling), but would also allow you to translate the chart if you wish by scrolling the view before the long press registers. I have figured out how to do all of the gesture interactions I want however I cannot figure out how to translate the chart.
All I'm really looking for is a API that allows me to translate the chart viewport by (dX, dY) in pixels but I can't seem to find anything. The closest I can find is CombinedChart.centerViewTo(...) but this expects you to center over data point values which if used when translating creates a bit of a staggered translation (as you cannot center over a value in-between two data points.
I can include code if needed, but I figured the code may be overly verbose for a simple API query.
So, I'll delete this when / if a better answer arises, but I found a way that suits my needs (yet may not be 'idiomatic'). What I did was the following:
(Given an offset in pixels of (dX, dY) and a CombinedChart named mChart...)
ViewPortHandler vph = mChart.getViewPortHandler();
Matrix transformation = vph.getMatrixTouch();
transformation.postTranslate(-dX, -dY); // unset the negs to make x / y inverted
vph.refresh(transformation, mChart, true);
So I am using MPAndroidChart as library for the viewing of graphs in my app. Now I wanted to make a LineGraph with several lines (n). The problem is that those lines do not have the same x-axis labels and I have not found a solution to put the x-axis labels in relation to the entries. Furthermore does the new line start at x-value 0. Therefore my lines do not fill the entire diagram area. Because when I have two lines with 6 entries each, the x-axis labels have the size 12. And therefore the lines end at half of the diagram.
How do I solve that?
Example LineGraph
I assume you mean the library available here: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java
From the code I grasped, LineChart does not support dual x-axis (while it support dual y-axis, left and right). See here , XAxis.java and YAxis.java
On the other hand, looks like the x-axis fits the data range automatically (there is no method to set min/max of x-axis).
An example of the graph >>
I would suggest you to re-organize your chart to switch x and y axis, and use two y axis if your series have different range of y values, but you want to show them in a chart. Double y-axis is more common than double x-axis from my experience, and easier to understand as well.
I am developing an Android app that plots the gyroscope sensor input in a graph with the GraphView 3.1 library.
The data that I am feeding the GraphView is values between -90 and 90.
Due to that I want the graph to show both positive and negative values, I consequently want origo to be in the middle of the graph (vertically).
Demo of the graph:
http://www.youtube.com/watch?v=NtQOVU0GEEY
As you can see in the video, the graph starts with the x- and y-axis values in the top/bottom, this is unwanted, as it the values are 0 in both cases. They should both be in the middle (vertical center i.e. origo) when the x- and y-axis are 0. The graph should never shift the curve depending on subsequent values either, which is shown as soon as I tilt the device.
Do any of you have an idea of how to fix this?
I would like the plot consistent and not relative to the subsequent values.
The code that I am using is almost identical to the one jjoe64 has created in his demo:
https://github.com/jjoe64/GraphView-Demos/blob/master/src/com/jjoe64/graphviewdemos/RealtimeGraph.java
Thanks!
Best Regards,
Tim
Try to fix the y bounds with the method
graphview.setManualYAxisBounds(-100d, 100d);
http://jjoe64.github.io/GraphView/com/jjoe64/graphview/GraphView.html#setManualYAxisBounds(double, double)
I've created a XYChart with numerical values different (for example temperatue with pressure) so I want to draw my own axeS just beside my chart. To do the following I've to unshow the YAxis, how should I do that ?
By using a trick: The Chart needs the Y Axis to remain in place so it knows where to render your content. You can, however, hide it. Hide the tick labels and set the axis' opacity to 0 using this code:
chart.getYAxis().setTickLabelsVisible(false);
chart.getYAxis().setOpacity(0);
The axis will still be there, but not shown.
I found that if I hid the chart using the following code:
chart.getXAxis().setTickLabelsVisible(false);
chart.getXAxis().setTickMarkVisible(false);
((Path)chart.getXAxis().lookup(".axis-minor-tick-mark")).setVisible(false);
Then I get about ~10 pixels less blank space on the bottom. IF the space was an issue for your application then you could use css offsets to correct it. This solution may have more predictable offsets.
SOLVED: I got this to work for sharing a common x-axis for two charts stacked vertically:
Create two charts, each with their own identical copy of the x-axis object, setting identical upper and lower bounds (optionally by binding).
Then hide the x-axis in the second chart like this:
chart = new LineChart<Number,Number>(xaxis2,yaxis2) {
{// hide xAxis in constructor, since not public
getChartChildren().remove(getXAxis());
// not getPlotChildren()
}
};
You'll want to set the widths of your y-axes to be the identical, e.g.
int w = 60;
yaxis.setMaxWidth(w);
yaxis.setMinWidth(w);
yaxis.setPrefWidth(w);
yaxis2.setMaxWidth(w);
yaxis2.setMinWidth(w);
yaxis2.setPrefWidth(w);