How to apply horizontal alignment in amchrts legend? - javascript

I'm using amcharts to create my chart, legend is in separate container.
Applying option
chart.legend.align = 'right'
has no effect
Codepen

If you're looking to align the contents of the legend, i.e. the legend items to the right, and not the entire legend itself (I am presuming this, because the legend is in an external, custom <div>, and this is taken straight out of our guides on the subject. If you meant something else please do let us know.), then you'll have to change its layout, then align its contents to the right via contentAlign. E.g.
// Align legend items to the right
chart.legend.layout = "vertical";
chart.legend.contentAlign = "right";
Here's a demo:
https://codepen.io/team/amcharts/pen/0aa8b7741a25a86fafa48b747077b8e3
I highly recommend checking out our guide, "Working with Containers", it contains various details regarding laying things out in amCharts v4. Also, once you align everything to the right, the legend is still going to be locked into the height of its html wrapper, i.e. 150px in your case, with no way to access the rest of the content. The demo above is a fork of what's found in our "Making the external legend scrollable" guide.

legend.align has no effect, because the width of the legend is 100%.
This is used by parent Container when layouting its children.
You should align the content with legend.contentAlign:
chart.legend.contentAlign = 'right';
Here I forked your code pen to show the result.
Another error in you code pen is the value of legend.valign
Valid values are:
"top" | "middle" | "bottom" | "none"
See VerticalAlign.
So you should set it this way:
chart.legend.valign = 'middle';

Related

How to expand chart to match width of container using ngx-charts

I'm trying to use ngx-charts to display an area chart that spans the full width of my page (it's supposed to match the width of the horizontal line above it). However, it appears that when generating a chart there is some sort of padding inside the svg, which I imagine is useful if you have a legend etc but I am not using that, here's what I see:
See how the actual area chart doesn't expand the full width?
My code:
<ngx-charts-area-chart
[scheme]="colorScheme"
[results]="heatmaps"
[curve]="curve"
[showGridLines]="showGridLines"
[tooltipDisabled]="tooltipDisabled"
(select)="onSelect($event)">
</ngx-charts-area-chart>
And my config variables in my component.ts
curve = d3.curveNatural;
showGridLines = false;
tooltipDisabled = true;
colorScheme = {
domain: ['#3f3f3f']
};
As you can see I am not using the view attribute so the chart should expand to the width of the page. I was thinking I could utilize a viewBox on the svg but not quite sure, any thoughts?
Thanks!

Kend0, legend of chart, title and scroll

Exist any possibility to add title to kendo legend (of chart) ?
My current legend looks:
item 1
item 2
I want to have:
LEGEND
- item 1
- item 2
Exist possibility to add scroll bar to kendo legend ?
(for example, height fixed to 200 px and when exist a lot of legend item - scroll bar)
Scrollbar in a legend :
It is possible but it is a lot of work. The legend is inside the SVG or Canvas, depending on your drawing mode. Scrollbars aren't really a thing in those environments. The easier approach is to write a custom widget of your own that is a legend in plain HTML. From the data in the Chart widget, you can get the list of legend items and their colors.
I had to implement this in Telerik Analytics, and it took a day or 2 to get right, but worked out in the end. Unfortunately, the code is proprietary so I can't share it here.

AmCharts how to set horizontal margin between columns?

I would like to ask, how to shrink space between grouped columns in AmChart library?
I tried to find it in documentation but without luck.
Thanks for any help.
See image:
Space between columns is set by chart.columnSpacing property. But I am not sure if this is the case, could it be you have some graph with missing data?
You can control the column spacing by changing the width(for columns) or height(bars) of the chart div element.

jqplot pie chart legend width

I'm trying to render the legend of a pie chart so that it has a fixed width, and when the labels reach that width (the div holder) to hyphenate on the next line. I tried the row option but it doesn't work very well because my data is dynamic and at times i have say 3 data sets, and each one of them gets rendered in a separate row, while at other times i have 15-20 data sets and it becomes messy.
Anyway the solution is to restrain the legend to the width of the div, that it is rendered into, yet it doesn't seem to be accepting any css alterations. I tried adding width:250px; to the "jqplot-table-legend" in jqPlot css, i also tried adding it into various places using Inspect Element in Chrome to test whether it works, but it doesn't seem to accept the new width. I also tried to hard code it into the javascript file at various places with no luck.
I'm not sure what I can add to the question in terms of code. Everything is pretty standard on the jqPlot side.
Any suggestions on how to get around this will be much appreciated.
This seems like the quick and dirty way, but it gets the job done. I'll use the jqplot.pieRenderer.js file as the example since it's easier to read than the minified version. Open the js file and scroll down to line 568. Right under
this._elem = $(document.createElement('table'));
this._elem.addClass('jqplot-table-legend');
add
this._elem.css({width: 300});
That will stretch the table out to whatever width you need it to be. Unfortunately, it also stretches out the column with the color swatch so you'll now need to scroll down a little further until you find
td1.css({textAlign: 'center', paddingTop: rs});
change that to
td1.css({width: 16, textAlign: 'center', paddingTop: rs});
and you should be all set.
Another method:
Just add these lines:
if (this.width) {
ss['width'] = this.width;
}
They allow you to set an arbitrary width in each different graph
You might also want to add these lines in jquery.jqplot.js (i.e if rendering bars)
Search for "createElement('table')" as described by mike
Worked for me

Highcharts problems: variable legend height

I have to set the height & width of the Highcharts placeholder. But the data to be displayed is variable. When the series names(long name) come to much more. The lengend height grows too high and hide the chart.
How could I solve this problem? Hoping to get some help.
I faced the same issue as you have mentioned. I was setting chart height and marginBottom property for the chart. I removed the marginBotton property and its working fine. AS your legend grows, the chart canvas area gets adjusted by itself and the legend does not overlap with the plot area
After your chart loads.. put this in your code..
$('.highcharts-legend').attr('transform', 'translate(50,400)')
But It will still move if you resize the browser...
Ill let you know if I figure it out..
As you can see here the release 2.2.4 introduces legend paging.
You can custom it following the reference.
As you add your series to the chart just stop adding them to the legend after a certain point (eg after 5) with the following option:
showInLegend: false
docs: http://www.highcharts.com/ref/#plotOptions-series
demo: http://jsfiddle.net/7Mmee/14/
see this jfiddle link.this is fiddle and highchart links
http://jsfiddle.net/highcharts/B9L2b/
I think this will solve your problem.

Categories