score:16
update: as of highcharts version 4.1.8 , see adam goodwin's answer, below.
for many years, the only way to set the maximum width of the columns, was dynamically via javascript.
basically:
- check the current bar width.
- if it is greater than desired, reset the series'
pointwidth
. - force a redraw to make the change visible.
something like:
var chart = new highcharts.chart ( { ... ...
//--- enforce a maximum bar width.
var maximumbarwidth = 40; //-- pixels.
var series = chart.series[0];
if (series.data.length) {
if (series.data[0].barw > maximumbarwidth) {
series.options.pointwidth = maximumbarwidth;
/*--- force a redraw. note that redraw() will not
fire in this case!
hence we use something like setsize().
*/
chart.setsize (400, 300);
}
}
score:0
i used the spacingtop attribute to enforce a maximum pointwidth on a bar chart:
if (series[0].data[0].pointwidth > maximumbarwidth) {
this.options.chart.spacingtop = this.options.chart.height - (maximumbarwidth * series.length) - 30;
this.isdirtybox = true;
this.redraw();
}
so if there is one bar over a certain width the spacing will be adjusted and the chart is drawn smaller.
this does not change the size of the container but keeps the bars beneath a certain size and your pointpadding and grouppadding will not be affected.
you could do the same with spacingright and would have a consistent chart without ugly spaces between the bars.
score:0
in my case, setting pointrange
to 1 was what i needed. if a category with a box was adjacent to a category without a box (only outliers in a scatter series) the box would be wider than the category.
there is a good explanation here.
score:0
i faced the same issue using highcharts and this is how i fixed it !!
-- create a wrapper div for the chart, with some minimum width and overflow:auto. (to enable horizontal scroll)
-- set the "pointwidth" of each bar to the required value. (say, pointwidth: 75)
-- now set the chartwidth dynamically, based on the number of bars.
use chartwidth = (number of bars) * (pointwidth) * 2
so, if you have 15 bars, chartwidth = 15*75*2 = 2250px, where 2 is used to create larger chart width, to accommodate spacing between bars.
--in this manner, you can have any number of bars of same width in the scrollable chart ... :)
score:1
function(chart){
var series = chart.series[0];
//--- enforce a maximum bar width
if (series && series.data.length) {
if (series.data[0].pointwidth > maximumbarwidth) {
for(var i=0;i< chart.series.length;i++)
chart.series[i].update({
pointwidth:maximumbarwidth
});
}
}
}
score:3
a better way would be has suggested
check this fiddle
just add
series: {
pointwidth: 20
}
in you plot options and thats it . :) enjoy cheers ...
score:13
ultimate solution is to wrap drawpoints
and overwrite shaperargs
of each point, especially x-position and width:
(function(h) {
var each = h.each;
h.wrap(h.seriestypes.column.prototype, 'drawpoints', function(proceed) {
var series = this;
if(series.data.length > 0 ){
var width = series.barw > series.options.maxpointwidth ? series.options.maxpointwidth : series.barw;
each(this.data, function(point) {
point.shapeargs.x += (point.shapeargs.width - width) / 2;
point.shapeargs.width = width;
});
}
proceed.call(this);
})
})(highcharts)
use:
$('#container').highcharts({
chart: {
type: 'column'
},
series: [{
maxpointwidth: 50,
data: [ ... ]
}]
});
and live demo: http://jsfiddle.net/83m3t/1/
score:28
obviously this question was asked a long time ago when this feature didn't exist, but as of highcharts 4.1.8 you can do this without any workarounds using the plotoptions.column.maxpointwidth
setting:
$('#container').highcharts({
/* other chart settings here... */
plotoptions: {
column: {
/* here is the setting to limit the maximum column width. */
maxpointwidth: 50
}
}
/* other chart settings here... */
});
below is the jsfiddle of the basic column chart example, modified to show this working:
and the documentation for this setting is here: http://api.highcharts.com/highcharts#plotoptions.column.maxpointwidth
Source: stackoverflow.com
Related Query
- Maximum bar width in Highcharts column charts
- Align second scatter series to the side similar to how column and bar charts do using HighCharts
- Highcharts | Label width control in bar charts
- How to reduce the space between Bars with a fixed bar width in Highcharts column chart?
- Highchart specific width stack column bar graph
- highcharts jquery dynamic change chart type column to bar
- Column width in Highcharts when combined with spline
- Highcharts spans beyond bootstrap column width when implemented as an angular directive
- Highcharts tootip for stacked bar charts
- Highcharts - Bar - Setting the X axis width and the chart area width to be constant
- Highcharts stacked column bar with line
- Highcharts markers on bar charts
- How to add a horizontal line in Column bar chart in Highcharts plugin?
- highcharts bar chart: columns width is very thin
- How to get current width of highcharts column
- Use of DotNet HighCharts dll to make charts in code behind
- Get the end points of each bar in a highcharts column chart
- set width of column in percentage in highcharts
- Dynamic position of tooltip in highcharts column charts
- Set different width for each column in highcharts
- Highcharts grouped bar charts with multiple axes
- Highcharts - Cannot set x-axes categories in column charts with negative values
- Make single bar in highcharts the width of the container
- how to show column and area charts with different y axis with same category and same x axis in highcharts
- How to change color of bar in column chart with different level of percentage in highcharts
- Highcharts - Column width not responsive
- Issue with last column width in Highcharts
- HighCharts issues in Dual axes, line and column charts
- add border color and width to 3d bar highcharts
- Highcharts - How do I keep both line points in from splitting between the two bar charts
More Query from same tag
- MySQL DateTime - XAXIS HIGHCHART
- Update HighCharts chart when AJAX Updates my data on my page
- "this.point.config" is not working anymore in highcharts tooltip
- Highcharts gauge incorrectly rendering label values
- Highcharts need parse data for showing points?
- dynamic highchart config in angular ui grid with angular js using pablojim's highcharts ng
- Is there a way to pass in variable element ID from Highcharts to launch a modal window?
- Highcharts touchscreens detection
- How to modify style properties in an Highcharts tag with Angular?
- White lines between heatmap cells when zooming in (browser zoom)
- HighCharts + xAxis label formatter
- How to define a javascript functions which creates highcharts on demand
- Constructing a combination chart with Highcharts
- Unable to rename Category column for Highcharts Pie chart
- How can I scrape Json data from Highcharts (stats.twitchapps.com)
- Ruby on Rails: How to generate an array from records to display in Highcharts?
- Highcharts - Hide series "points" (labels) on both x- and y-axis
- How to remove white borders on bar charts in highcharts?
- Finding parent of highcharts button w/ jquery
- Dependency-Wheel item without connection
- HIghcharts.js add catgories with addseries on column chart
- Proportional Pie-charts using High-Charts
- HighCharts Time-based Quarterly Data - xAxis Label Issue
- jQuery - Div doesn't fit page content
- What's the code in Highcharts such that the bars (columns) in the same group use the same color?
- how do I process dynamically generated graph with PHP and send the result as an email?
- Binding empty array to chart
- HighCharts - applying a formatting function over plot options
- High Charts : Two lines showing instead of one
- convert list<int> to object