Cannot reposition axes in bar graph OxyPlot xamarin - android

I have displayed a bar graph in android xamarin. I want to display a simple bar graph with 3 categories.
What I want:-
What I get :-
So currently my graph is showing horizontally. I want it to show as in figure 1.
Here is my code:-
var plotModel1 = new PlotModel();
plotModel1.LegendOrientation = LegendOrientation.Vertical;
plotModel1.PlotAreaBorderColor = OxyColors.White;
var barSeries1 = new BarSeries();
for (int i = 0; i < barValues.Length && i < colorPallete.Length && i<barTitles.Length; i++)
{
barSeries1.Items.Add(new BarItem(barValues[i], -1) { Color = OxyColor.Parse(colorPallete[i]) });
}
plotModel1.Series.Add(barSeries1);
MyModel = plotModel1;
barPlotView.Model = MyModel;

Instead of BarSeries you should look up ColumnSeries. It will give you the horizontal graph you are looking for.

Related

Add polyline to google maps with different colors android

I'm trying to get coordinates from Firebase to create polyline on Google maps with different colors to each user. The problem is when I get this data and insert it on google maps it shows with the same color.
List<Integer> colors = new ArrayList<>();
colors.add(-9784993);
colors.add(-6501807);
for (int a = 0; a <= userList.size()-1; i++) {
for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {
dataClass d = objSnapshot.getValue(dataClass.class);
LatLng start = new LatLng(d.getLat(), d.getLongi());
elasticList.add(start);
polylineOptionsTest[a] = new PolylineOptions()
.addAll(elasticList)
.color(colors.get(a)) //Get color from list called "colors"
.clickable(true);
polyline2 = mMap.addPolyline(polylineOptionsTest[a]);
}
}
Probably that is because userList.size() is equals 1 and colors.get(a) always returns colors[0] (-9784993) color. In other words you add polylines for single user.
Update: mistake is in for loop - you should use:
for (int a = 0; a <= userList.size()-1; a++) {
instead of
for (int a = 0; a <= userList.size()-1; i++) {
you increase i variable, not a.

MPAndroidChart Legend with different shapes (forms)

I am using MPAndroidChart and have the need to plot a number of datasets using ScatterChart. As the number of datasets is dynamic, I used a logic that creates a combination of color and shape for each dataset. The resultant chart looks like this. As you can see, in this example, there are ten datasets, each represented by a unique Shape+Color combination. The problem is with the legend shapes. How do I change the legend shapes to match with the dataset shapes?
Chart:
Source Code:
private static final int SCATTER_SHAPES_MOD = 4; //there are four shapes
private static final int SCATTER_COLOR_MOD = 5; //there are five colors
for (int i=0; i < dataSeries.size(); i++) {
ScatterDataSet set = new ScatterDataSet(dataSeries.get(i), choiceArray[i]);
set.setScatterShape(ScatterShapeArray[i % SCATTER_SHAPES_MOD]);
set.setColor(ColorTemplate.COLORFUL_COLORS[i % SCATTER_COLOR_MOD]);
set.setScatterShapeSize(10f);
set.setDrawValues(false); // Hide data labels
dataSets.add(set); // add the dataset
}
if (dataSeries.size() > 0) {
data = new ScatterData(xVals, dataSets);
// Set chart data
chart.setData(data);
}
Actually, now Dear Philipp has added that functionality, I think he forgot to update here, hence I am updating so that for someone it may help.
There is a new function called setCustom in legend class which can be used for the above purpose.I have tested it.Please find code below. The looping is done with dataSets I had already(ScatteredDataSet in my case).
List<LegendEntry> entries = new ArrayList<>();
for (int i = 0; i < dataSets.size(); i++) {
final LegendEntry entry = new LegendEntry();
IScatterDataSet set = dataSets.get(i);
String Label = set.getLabel();
if (Label.equalsIgnoreCase("A")) {
entry.form = Legend.LegendForm.CIRCLE;
entry.formColor = set.getColor();
entry.label = Label;
} else if(Label.equalsIgnoreCase("B")){
entry.form = Legend.LegendForm.CIRCLE;
entry.formColor = set.getColor();
entry.label = Label;
} else if(Label.equals("C")){
entry.form = Legend.LegendForm.SQUARE;
entry.formColor = set.getColor();
entry.label = Label;
}
else if (entry.formColor == ColorTemplate.COLOR_NONE ||
entry.formColor == 0) {
entry.form = Legend.LegendForm.EMPTY;
entry.label = Label;
}
entries.add(entry);
}
LegendEntry[] mEntries = entries.toArray(new LegendEntry[entries.size()]);
Legend l = mChart.getLegend();
l.setCustom(mEntries);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setXOffset(10f);
I Thank Philipp for this awesome library.
NOTE:Only limitation I see is that LegendForm has only few shapes as enum which can't be altered and Scatter chart has more shapes which can't be replicated in Legends!If there is a way please post here.
Unfortunately that is currently not possible by default.
You will have to modify the library to get the behaviour you are describing.
I might add a feature like that in the future.

Android GraphView Bar chart Multiple series

Hi i have a Bar graph using android GraphView. have 3 series that i need to pass into it but its currently drawing all 3 series onto of each other is there a way to change the width of the bar so that it shows
heres what i have sofar
try{
JSONArray graphArray = returnGraphyArray(statistics);
if(graphArray != null){
int graphLength = graphArray.length();
GraphViewData[] calls = new GraphViewData[graphLength];
GraphViewData[] length = new GraphViewData[graphLength];
GraphViewData[] transfered = new GraphViewData[graphLength];
for(int r = 0; r < graphLength; r++){
JSONObject row = graphArray.getJSONObject(r);
calls[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("total_calls")));
length[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("avg_call_length"))/60);
transfered[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("calls_transferred")));
}
GraphViewSeries totalCallsSeries = new GraphViewSeries( "Total Calls", new GraphViewSeriesStyle(getResources().getColor(R.color.pink), 5),calls);
GraphViewSeries totalCallLengthSeries = new GraphViewSeries( "Total Call Length", new GraphViewSeriesStyle(getResources().getColor(R.color.green), 5),length);
GraphViewSeries totalCallsTransSeries = new GraphViewSeries( "Calls Transfered", new GraphViewSeriesStyle(getResources().getColor(R.color.blue), 5),transfered);
BarGraphView graphView = new BarGraphView(context, "");
graphView.addSeries(totalCallLengthSeries);
graphView.addSeries(totalCallsTransSeries);
graphView.addSeries(totalCallsSeries); // data
graphView.setHorizontalLabels(bottomlabels);
graphView.setShowLegend(false);
graphView.setLegendAlign(LegendAlign.TOP);
graphView.setLegendWidth(SM_Global.pxFromDp(context, 100));
graphView.getGraphViewStyle().setNumHorizontalLabels(6);
layout.addView(graphView);
}else{
layout.setVisibility(View.GONE);
ImageView legend = (ImageView)v.findViewById(R.id.graph_legend);
legend.setVisibility(View.GONE);
}
According to the GraphView website:
"Note: It is currently not possible to plot multiple bar charts. To say it more in detail: It is possible, but the bars will be rendered at the same position and so they will be overlapped."
I would suggest using AChartEngine instead. Here's the link to the jar file
https://code.google.com/p/achartengine/downloads/list
and here's an example
http://wptrafficanalyzer.in/blog/android-drawing-bar-chart-using-achartengine/

Rating bar like android in codename one

I want to add Add Raring Bar in a Form of codename one like android.. But am afraid there is no GUI for to create in codename one.. Is there any other option for to create it..
I think someone contributed a component like that on the discussion forum once, but I can't find the link.
It should be relatively simple to create using something like this (didn't test this code though):
Container starSelect = new Container(new BoxLayout(BoxLayout.X_AXIS));
for(int iter = 0 ; iter < 5 ; iter++) {
createStarButton(starSelect);
}
void createStarButton(final Container parent) {
final CheckBox cb = new CheckBox();
cb.setToggle(true);
cb.setIcon(unselectedStarIcon);
cb.setPressedIcon(selectedStarIcon);
cb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if(cb.isSelected()) {
boolean selected = true;
for(int iter = 0 ; iter < parent.getComponentCount() ; iter++) {
Component current = parent.getComponentAt(iter);
if(current == cb) {
selected = false;
continue;
}
((CheckBox)cb).setSelected(selected);
}
}
}
});
parent.addComponent(cb);
}
I'am not iOS developer but i can provide some links please try
1.DLStarRating
2.RatingBar
3.XLRatingBar
4.Sample RatingBar Project

Dynamically add page numbers in android

I am stuck with an issue in my project.The need is to show all data fetched from server using webservices.I successfully get data from server using json.but i want to show data on screen in tabular format 50 records at a time.Please suggest me how to do this or if you can guide me through a better way to implement paging in android.
The code of paging is here :
Implement Pagination on tab layout
and the function i use to append rows dynamically to tablelayout is :
private void appendRows(TableLayout table, String[] data) {
int rowSize = data.length;
int colSize = (data.length > 0) ? 1 : 0;
for (int i = 0; i < rowSize; i++) {
TableRow row = new TableRow(this);
for (int j = 0; j < colSize; j++) {
String[] rowVal = null;
rowVal = data[i].split(",");
for (int k = 0; k <= rowVal.length - 1; k++) {
TextView c = new TextView(this);
c.setText(rowVal[k]);
c.setTextColor(getResources().getColor(R.color.white));
c.setPadding(3, 3, 3, 3);
row.addView(c);
}
}
table.addView(row, new TableLayout.LayoutParams());
}
}
Please guide me I need to show hyperlink page numbers at the bottom of my window as shown in google
This might be of some help. Its a tutorial for pagination. Here is the source code.
I have had similar requirement like yours and I normally use the listview for it. Due to the recycling of views it is a lot more efficient than using a table layout.
You can create a custom adapter where you always return the size as 50+1, 100+1. So in your onItemClickListener you can check if the row position is more than the items, if so, then you add the next 50 items to the adapter. This is a basic idea of how to do it.

Categories

Resources