Positioning ZedGraph legend at middle right not top right? - graph

Is there some way to position the legend using ZedGraph so that it is on the right-hand side, but vertically centred. Using:
output.Legend.Position = ZedGraph.LegendPos.Right
positions the legend at the top right, but beside a pie chart this looks misaligned. Is there a way to get the legend to vertically centre?
Changing output.Legend.Location.Y seems to have no effect, nor does trying output.Legend.Location.AlignV = ZedGraph.AlignV.Center
Added in response to first answer below...
Floating, reducing the chart size and positioning the label does centre vertically, and is better than I had managed previously. Unfortunately it has a side-effect, in that the legend switches to multi-column and tries to occupy half the width of the total chart area, thus usually overlapping the chart (see picture). Looking at the ZedGraph source, this wider mode is used for all layouts except Left and Right.

Location is only enabled when Legend.Position is set to Float.
You could do like this (C#):
output.Legend.Position = LegendPos.Float;
output.Legend.Location =
new Location(1.05f, 0.5f, CoordType.ChartFraction, AlignH.Right, AlignV.Center);
with the probably undesired "feature" that the legend is drawn partially inside the chart:
To workaround this issue I believe you also have to manually resize your chart:
output.Chart.Rect = new RectangleF(xstart, ystart, xsize, ysize);

Anders' answer nearly worked, except it had the side-effect of changing the width of the legend. This led me to download the source code to find out why, and I discovered that the legend positioning code is actually quite trivial. LegendPos.Right is only referenced twice in the code, both times in Legend.CalcRect
Adding a new LegendPos.MiddleRight only needs it added to the enum, a case for MiddleRight added to the first Switch which runs the same code as Right. And in the second Switch in CalcRect the following:
case LegendPos.MiddleRight:
newRect.X = clientRect.Right - totLegWidth;
newRect.Y = tChartRect.Top + tChartRect.Height / 2 - totLegHeight / 2;
tChartRect.Width -= totLegWidth + gapPix;
break;
This is the same code as for LegendPos.Right except for the newRect.Y line.

Related

Unwanted overlapping text in watch glance

In my watch glance I have selected the following layout in IB:
For some unknown reason the two top labels want to overlap...sometimes. Like this:
My understanding is that it shouldn't be possible to overlap labels using watchkit. Any idea of how to solve this problem?
I have often found that when labels are not in a Group container, the layout can be unpredictable. I would recommend placing the two top labels in a Group and then make the first Vertical Position Top and the second Vertical Position Bottom. Also be sure to set both labels to use "size to fit content."

dc.bar-chart margin and axis label size adjustment

I found my yAxis label too big to be shown--it was truncated by the left border.
I tried increasing the left margin, with no success. It seems that the label text is left-aligned. So increasing the margin only gets the label further away from the ticks text.
Please see the attached screenshots. The one with wider gap is margin.left=70. The other one is with margin.left=40. No matter which case, the 'Expenditures' seems to be truncated on the left side.
Is there anywhere in the dc.css that I can change this configuration?
Thank you!!
You can adjust where the axis labels are placed relative to the edge by using the second parameter when you call the .xAxisLabel() and .yAxisLabel() methods. This sets the "padding" (actually the offset from the left/bottom).
coordinateGridMixin.xAxisLabel docs
coordinateGridMixin.yAxisLabel docs
It's confusing that the text size gets set through the stylesheet but the positioning can't be. I'm not sure if there's any way around this, though

Flex Chart Axis style: what is this style called?

I'm having difficulty with Flex charts. I'm working on a complete rewrite of a flex app that has a fair bit of charting involved, and I've been instructed to get the look and feel as close to the previous version as possible (for the initial release).
I can't seem to find the style property which dispays a blue, tabbed sort of effect of the chart axes. As I don't have the rep to post an image, I'll direct you to the adobe live docs 'using line charts' page (sorry, I can only post one link because of the anti spamming mechanism, see link in the edit below) - the effect is present on the vertical axis of the chart at the top of the line charts examples page.
It seems to be some kind of default setting, but I have not been able to pin it down, not even when copying chunks of the old code.
If anyone has any ideas as to how to get hold of this style, or as to what could be removing this style, I'd be extremely grateful.
Thanks for reading.
Edit:
Sorry I will try to clarify:
If you look at the chart at the top of the using line charts page in the Adobe Live docs, the vertical axis has a thick, blue tabbed style, but the horizontal axis does not.
I am trying to gain control over this blue tabbed style - specifically I want to make it appear on the horizontal axis and remove it from the vertical axis of a line chart. However, I cannot find the property which sets this style.
I know it is possible to alter this style, as I have seen examples of charts with the look I need, however there does not appear to be an obvious way to alter it.
I hope this is a bit clearer. Thanks.
The blue bar that comes by default is a stroke. The white divisions within it are minor ticks.
To style it differently, you need four parts:
a chart (e.g. LineChart)
an Axis (e.g. LinearAxis)
an AxisRenderer
a Stroke (e.g. SolidColorStroke)
Then you'll have to connect these parts:
var chart = new LineChart();
var vAxis = new LinearAxis();
var stroke = new SolidColorStroke();
stroke.caps = CapsStyle.NONE;
stroke.weight = 1;
stroke.color = 0x000000;
var axisRenderer = new AxisRenderer();
axisRenderer.axis = vAxis;
axisRenderer.setStyle("axisStroke", stroke);
// Only if you don't want minor ticks to display:
axisRenderer.setStyle("minorTickPlacement", "none");
chart.verticalAxis = vAxis;
chart.verticalAxisRenderers = [axisRenderer];
You'll find more on the topic here: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7c65.html
Its not enough clear for me, what do you want, but if you are looking for styling of charts look this, but if something about axis look this.
Anyway you should explain your goals, so we could help you.

In flex, how to get correct Y-axis when there is a vertical scroll?

In flex, I am getting the y-coordinate in the following way:
nextHBox = HBox(ingBox.getChildByName("ing" + nextId));
nextYAxis = ingBox.localToGlobal(new Point(nextHBox.x,nextHBox.y)).y;
newCanvas.x = nextYAxis;
nextYAxis gives me the y-axis and I use it to position new component. It works absolutely fine. But, when there is vertical scroll, and I scroll it a little bit, and then the above mentioned code places the component at wrong place. I believe, it has something to do with the scroll.
You can factor in the scroll position of the parent container by adding the value of its verticalScrollPosition property to your y position.

Flex - Placement of Legend for a chart

I would like to be able to specify the placement of a legend for a linechart. Currently, it continues to appear to the right of the chart. I have tried playing with the width/height of the chart to no avail... Putting the legend before the linechart in the mxml causes it to appear to the left. I can't seem to get it appear at the bottom though. I can't seem to find any good examples for this. They don't seem to specify anything but the legend usually shows up below the chart, I can't seem to do it. Optionally, it would be okay to somehow minimize the legend..
what container are your line chart and legend in? its sounds like you are using either an HBox or an application with the layout="horizontal". To move the legend below use either a VBox or application layout of vertical. Or you can use a canvas and use constraints (left, right, top, bottom) or x and y coordinates

Resources