Chart with pair of lines with single legend entry - android

Specifically, with MPAndroidChart I'm trying to create bollinger bands on a LineChart. I'd like both lines to be the same color and share a single legend entry but I can't seem to find a way to do this. It seems if I have 2+ lines I need to have 2+ legend entries.
Also is there a way to stack the legends vertical when positioned below the graph?

What you mentioned is just the Legend that is auto generated depending on your data.
But the Legend also has a setCustom(...) method that allows you to set any amount of colors and labels that you like.
Legend l = chart.getLegend();
l.setCustom(integerColorArray, stringLabelArray);
More on that in the wiki.

Related

How to add legend for Pie chart in Android plot?

I am using Android Plot(http://androidplot.com/) library to draw a Pie chart and Pie chart draw is fine but I want legend and its customisation as shown in attached image so please guide me to do same in Android Plot library.
Pie chart legends were added in Androidplot 1.5.0 but is disabled by default. To enable:
pieChart.legend.setVisible(true);
Configuration of the legend works the same way it does for other series types in Androidplot. For example, you can configure a single column with 4 rows:
pie.getLegend().setTableModel(new DynamicTableModel(1, 4));
Or a single row with 4 columns (shown below):
pie.getLegend().setTableModel(new DynamicTableModel(4, 1));

androidplot dual data-series legends with range legends on both sides (left, right)

while i really appreciate the new 1.4.x androidplot release for it's ability to provide range legends on both sides (left and right), this would now ask for being able to provide 2 visually separable data series legend blocks instead of one or a similar setup
back in the 0.9.8 days i created 2 independent plots being overlayed ... this allowed a range legend on the left with one plot and one on the right with the second one ... now i was able to place one data series legend inside the graph in the upper left corner and the other one in the upper right corner
this visually linked the left and right range legends to it's data series legends
upon a touch in the either left or right range legend screen areas would scroll (change) through the various data series linked to each plot and the data series legends on each side would provide a visual help which series are linked to each side (back then plots)
i also changed the grid params and domain label color to indicate which range legend is the one applied to the grid setup
i prefer not to use the dual plot approach for performance reasons over a faster single plot setup
i can accomplish most of the above described functionality with the 1.4.3 rev of androidplot, except i have no means to provide 2 visually separated data series blocks legends relating to the 2 range legends on the left and right
i hope this was not a too complicated description to my desired setup
sine test data screenshot showing 2 data series legends with dual plot implementation on 0.9.8
thanks for your suggestion
yes, i could live with it for now ... actually i took the default horizontal legend position at the bottom and moved it into the graph area at the bottom to provide a bigger graph area and the legend still goes from left to right, and it's not too likely that this will be mostly overwritten with the plots
i'm already adding the left plots 1st and the right ones after, so i have some sort of visual left and right separation
it would be nice to maybe later have some sort of ability of physical separation for the data series legends, like with the left and right range legends
the issue seems to be the automatic legend data generation based upon the plot.addseries function ... if this automation is removed and a solution in concept similar to below
XYLegendWidget lw = Plot.getLegend (right ? XYLegendWidget.Edge.RIGHT
: XYLegendWidget.Edge.LEFT) :
lw.addSeries (LineAndPointFormatter reference or similar ) ;
lw.setPadding (1, 1, 1, 1) ;
lw.setIconSize (new Size (isz, SizeMode.ABSOLUTE, isz, SizeMode.ABSOLUTE)) ;
lw.getTextPaint ().setTextSize (txtsz) ;
lw.getTextPaint ().setTextAlign (Paint.Align.RIGHT) ;
lw.getTextPaint ().setColor (ContextCompat.getColor (this, R.color.gray)) ;
lw.position (spc, HorizontalPositioning.ABSOLUTE_FROM_RIGHT,
bot, VerticalPositioning.ABSOLUTE_FROM_BOTTOM, Anchor.RIGHT_BOTTOM) ;
the above code is taken from my setup, except for the lw.addSeries (LineAndPointFormatter reference) or similar
use the LineAndPointFormatter data already available from the 2nd param in the plot.addseries and use it for an addseries call in the XYLegendWidget setup
just a thought ... this would now provide 2 legends ... of course the automated legend data generation based upon plot.addseries is now gone and the legend, even one needs to be setup manually
but you are the expert Nick, and thanks for the nice work with 1.4.x, despite some growing (upgrade) pains for some less experienced users like myself

Make the miniature squares under a barGraph scrollable using mpandroidchart

I have a barGraph similar to the one below.
I was wondering if the miniature ( maybe the word is not accurate, I'm talking about the little coloured squares under the x axis, on the left of the word "Company" on the picture ) can be set to scrollable when the graph contains a lot of datas.
If so, is there as well a way to set those squares touchable and on touch, to center the view on the corresponding element of a barGraph?
I add that the graph itself is and has to be scrollable.
Thanks in advance.
The little squares you are talking about represent the Legend which shows the different datasets used.
It is not possible to make this scrollable by default.
What you could do is create your own miniature BarChart below your actual barchart and use that one.

achartengine: line chart with threshold

I use achartengine in my Android application and has been able to draw few line charts. Now I need to draw some kind of threshold line which basically an extra line in red that will run at certain Y value across the graph.
I read other questions regarding threshold lines but mostly about bar chart to have different color above and below threshold line. I need it for line chart and I don't need different color above and below the threshold line.
I can definitely draw it as another line, but I don't want legend for this shows up while I still want legend for others show up. Is there any way to do this? I don't know if there is built-in functionality to draw the threshold line. Or at least a way to hide legend for only one line.
Any input, suggestion or direction will be very appreciated. Thank you.
Got it. If anyone needs to do the same thing, this is what I do:
if(i == theIndexForThresholdLine) {
renderer.getSeriesRendererAt(i).setShowLegendItem(false);
}
That will turn off legend only for that item.

achartengine - inclined labels position

I'm using achartengine to show a temperature graph. on X axis I put dates, to fit them I call setXLabelsAngle(45); this is the result:
As you can see, the labels are placed too high and go over the x-Axis. How could I fix this? I'm already using setMargins(), but labels don't move, only legend does.
This will help:
renderer.setXLabelsAlign(Align.LEFT);

Categories

Resources