I need to deal with large array data in Highcharts and I need to increase the height in Y-Axis and width in X-Axis with scrollbar. How to do this?
My JSFiddle : http://jsfiddle.net/ngendk2o/3/
You can manually increase the height and width of your chart. For example, use:
chart: {
/* ... */,
height: 800,
width: 2000
}
It will automatically add scroll-bars to your page.
See your JSFiddle here: http://jsfiddle.net/ngendk2o/4/
Related
I have one dataset with multiple labels in my bar chart. When bar chart has more labels, width of label shrink for each.
I want to set fixed width for every window in my chart. For example dark stick for every label should be same fixed width size no matter how many window exists.
Thank in advance.
Is it a request to have the vertical axis have a fixed width?
There is a way to do this:
options: {
scales: {
yAxes: [{
afterFit: function(scaleInstance) {
scaleInstance.width = 100; // sets the width to 100px
}
}]
}
}
I am using the horizontal bar chart from chartjs. Right now my Chart seems to be very big, and the space between the ticks on the xAxis is very high. ( I attached picture of that), can anyone tell me how to reduce this space and scale the chart in total better?
My css properties:
#myChart {
width: 90% !important;
height: 100% !important;
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
padding-bottom: 5%;
}
My chart options:
modelChart = new Chart(ctx, {
type: 'horizontalBar',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
suggestedMin: 0,
fontSize: 18
}
}],
xAxes: [{
ticks: {
autoSkip: false,
fontSize: 18,
beginAtZero: true
}
}]
},
legend: {
display: false
},
tooltips: {
footerFontSize: 22,
bodyFontSize: 22,
titleFontSize: 18
},
hover: {
animationDuration: 0
}
}
});
If you post your corresponding HTML then I can confirm this, but is #myChart the id of your canvas element or of a div that contains your canvas element?
Chart.js will render the chart such that it fully fills the parent of the canvas element. Even if you set a width property on a canvas element it will still not affect the chart size.
Checkout this codepen example that demonstrates the difference. At the top is a chart contained by a div whose width is set to 40%. At the bottom is the same chart but the canvas element's width is set to 40%. Notice that the second chart still fills the entire window.
So long story short, you should wrap your canvas element in a div and set the div's desired size accordingly to actually change the size of your chart.
Now, let me address your question about changing the space between ticks in your X axis. There is not really a way to truly do this like I think you are wanting to do, because chart.js determines the tick placement by dividing the width of the chart by the number of tick steps (e.g. it always uses the full width of the chart equally).
So one way to decrease the space between ticks is to simply add more ticks (by changing the tick stepSize using the stepSize and fixedStepSize properties). Obviously, in this case, the chart size has not changed. You are just showing more ticks, so the space between them has decreased.
If you want to truly change the distance between ticks, then the only way is to decrease the width of the chart. But by default, the height of the chart will decrease along with the width because the maintainAspectRatio property is defaulted to true.
So if you want a narrower chart (but still want the chart to be large) then I would advise you to set the maintainAspectRatio property to false and manually set the height and width of your chart's parent div.
Checkout this codepen that gives an example of each of the tick spacing concepts that I discussed.
The first chart is the baseline, the second chart adds more ticks (thus decreasing the tick spacing), and the third chart changes the aspect ratio so the chart is still large but narrower (therefore the distance between ticks is reduced).
Try using chartArea: {width: '30%'}. Adjust percentage as per requirement. It will compress the width of the chart. Just a thought !!!! I used in horizontal bar graphs to adjust my graph size.
Does anyone know of a good way to change the legend size in highmaps? Here is a fiddle in which the width and itemWidth properties of the legend are set. I found this solution searching the forum and this solution works for charts. Exmaple:
Highcharts set legend height
But I can't find a good way to do it for maps.
http://jsfiddle.net/meo67rhf/
legend: {
width: 200,
itemWidth: 200
}
I've also tried stetting the width use DOM methods:
i.e. document.getElementsByClassName("highcharts-legend").style.width = "200px";
Neither of which are working for me. I'm just trying to modify the height and width of the legend. Any help is appreciated.
You're on the right track with this one.
Yes, Highmaps can adjust the size of the legend, too. I'm not sure what you're looking to do, but the height is automatically defined by the number of elements that are included inside. You can play around with this by changing the values of width, itemWidth, and layout.
In your example fiddle, if you change the values above, you'll get a different layout. See what happens when you shift them to:
width: 300,
itemWidth: 100,
layout: 'horizontal',
You get the following:
The white box is taking on the defined width of 300. Setting the itemWidth of 100 means the individual legend items will take on 1/3 of the total defined width (just don't use percentages; that won't work).
One extra thing you could also do is have these values be percentages of the container element. If you have the container's width and/or height defined in a stylesheet declaration, you can set JavaScript variables to capture those values on runtime and adjust your legend accordingly.
For example:
// in your inline stylesheet
#container: { width: '650px', height: '450px' }
// variables defined before your chart options
var chartHeight = $('#container').height();
var chartWidth = $('#container').width();
// in your legend
width: chartWidth * 0.3, // 30% of total width
itemWidth: chartWidth * 0.1, // 10% of total width
Setting the layout to 'horizontal' will give you a legend that's shorter than if you had used the value vertical.
I hope all of this is helpful for you.
Here is a JSFiddle of what I currently have:
http://jsfiddle.net/DGwcF/
I have set both the margin and spacing to 0, though the padding still remains around the chart itself.
How do I make the chart go all the way to the edge of the container? Thank you!
You need to set pane's size as 100%, see this:
http://jsfiddle.net/DGwcF/3/
pane:{
size: '100%',
}
It's possible to set the width of the chart "area" ?
I mean not the whole chart only the part with curves.
Or maybe an other solution is to set the x-axis width.
Regards
Indeed, you can set for xAxis width that way:
xAxis: [{
width: 200
}]