Hi in my app I made this graph !I´ve set renderer.setXAxisMin(0) but the first label of x axis is always hidden even if I try to use negative values the label do not appear. Thanks in advance
graph
My code :
mRenderer.setMargins(new int[] { 30, 25, 20, 45 });
mRenderer.setApplyBackgroundColor(true);
// SET THE BACKGROUND COLOR
getUnits(units);
mRenderer.setBackgroundColor(Color.parseColor("#339999"));
mRenderer.setAxisTitleTextSize(TEXT_SIZE_HDPI);
mRenderer.setChartTitleTextSize(TEXT_SIZE_HDPI);
mRenderer.setLabelsTextSize(16);
// mRenderer.setPointSize(TEXT_SIZE_HDPI);
// mRenderer.setXTitle(getResources().getString(R.string.date));
mRenderer.setXLabelsColor(Color.WHITE);
mRenderer.setYLabelsColor(0, Color.WHITE);
// mRenderer.setYTitle(getResources().getString(R.string.weight));
mRenderer.setFitLegend(true);
mRenderer.setMarginsColor(Color.parseColor("#339999"));
mRenderer.setPanEnabled(true, true);
mRenderer.setScale(1);
mRenderer.setXAxisMin(0);
mRenderer.setInScroll(true);
mRenderer.setShowGridY(false);
mRenderer.setAntialiasing(true);
mRenderer.setZoomEnabled(false, false);
mRenderer.setShowAxes(false);
mRenderer.setShowGrid(false);
Related
With data: [null, null, 10, 20, 20, 33, 23, 23, 22, 5]
How can i build a hashed region in Highcharts, like displayed to the left of the blue columns, the hashed region would represent a group of null data points?
I had thought to overlay 2 chart types to solve this. Wondering if anyone has a better idea here? Maybe using Renderer or an area line chart?
you can use Plot bands
In chart option add following
Fiddle
events: {
load: function () {
var series_data=this.series[0].data;//this is series data
for(var i=0;i<series_data.length;i++){
if(series_data[i].y==null){//find null value in series
//adds plot band
this.xAxis[0].addPlotBand({
from: i-1, //point back
to: i+1, //point after
color: '#c5d8f7',//this color represent null value region
});
}
}
}
}
I have a column chart that has yAxis labels inside the plot area. DEMO: http://jsfiddle.net/o4abatfo/
This is how I have set up the labels:
yAxis: {
labels: {
align: 'left',
x: 5,
y: -3
}
}
The problem is that the leftmost column is so near the plot area edge that labels are overlapping it. Is there a way to adjust the plot area padding so that the columns would start a bit further on the right?
You can set min value as -0.49.
http://jsfiddle.net/o4abatfo/2/
One possible solution:
Keep the labels on the outside, and apply the plotBackgroundColor as the chart backgroundColor.
This means that the legend will be encased in the background color too, but, again, it's on option.
Example:
http://jsfiddle.net/jlbriggs/o4abatfo/11/
I asked the same thing in the Highcharts forum and got this solution as a reply from #paweł-fus:
var chartExtraMargin = 30;
Highcharts.wrap(Highcharts.Axis.prototype, 'setAxisSize', function (p) {
p.call(this);
if (this.isXAxis) {
this.left += chartExtraMargin;
this.width -= chartExtraMargin;
this.len = Math.max(this.horiz ? this.width : this.height, 0);
this.pos = this.horiz ? this.left : this.top;
}
});
However, adding this made the tooltips appear in the wrong position. This was fixed by overriding the Tooltip.prototype.getAnchor() method and adding the extra margin in the x coordinate:
Highcharts.wrap(Highcharts.Tooltip.prototype, 'getAnchor', function(p, points, mouseEvent) {
var anchor = p.call(this, points, mouseEvent);
anchor[0] += chartExtraMargin;
return anchor;
});
I've set
pointWidth: 20,
pointPadding: 0,
groupPadding: 0
But the chart still expands to fill the default chart height. Is it possible to have Highcharts adjust the chart height instead?
http://jsfiddle.net/MLELM/
The chart will fill the available height with what you give it.
point and group padding are a proportion of the available space, so the chart is honoring the properties as specified.
It uses the size of the containing element to determine its size, so it cannot possibly ignore the height of the containing element.
If you want a smaller chart that fills a larger space on your page, you can put your containing element in another wrapper element. Then you can calculate yourself how tall your chart should be based on the number of series, and pass that height to the container.
If you want to have the series that you have specified clustered near the top, you will need to add additional null data points to fill the space below them.
If you can be more specific about what you want and why, better answers may be available.
[[ update
Stumbled across this post again, and remembered that I have a demo that automatically sets the chart height based on some predefined parameters, and the number of data points.
var barCount = chartData.length,
pointWidth = 20,
marginTop = 70,
marginRight = 10,
marginBottom = 50,
marginLeft = 100,
groupPadding = 0,
pointPadding = 0.3,
chartHeight = marginTop
+ marginBottom
+ ((pointWidth * barCount)
* (1 + groupPadding + pointPadding));
Fiddle here:
http://jsfiddle.net/jlbriggs/kpu5d1qf/
Related question here:
How to calculate the height of bar chart
Yes, you can set the chart height like that:
chart: {
type: 'bar',
height: 200,
},
See also http://jsfiddle.net/MLELM/3/
I want to draw a background behind a plotLine label in a highstock chart.
Using an example from the Highstock API, I came up with this code (crt is the chart object):
var textbox = crt.yAxis[ 0 ].plotLinesAndBands[ 0 ].label;
var box = textbox.getBBox();
crt.renderer.rect(box.x - 3, box.y + 1, box.width + 6, box.height, 3).attr({
fill: '#0c0',
id: 'labelBack',
opacity: .7,
'stroke-width': 0,
zIndex: 4
}).add();
This draws a semi-transparent box behind the label as intended (the label has zIndex 5). However when the chart is resized, the box maintains the same position relative to the top-left of the chart, causing misalignment with the label text (the position of the label changes because of the chart resizing).
I tried using the chart redraw event for this, but even though I can see that the event is fired, and the function is executed again, no other boxes are drawn (I was trying to get more boxes to appear on each redraw, planning to solve removing obsolete boxes in the next iteration).
How can I solve this?
It feels more like a hack than a genuine solution, but I have come up with a workaround that solves my issue for now, I have the function below:
var labelBackground = null;
function labelDrawBack(crt) {
if ( isIntraDay ) {
var textbox = crt.yAxis[ 0 ].plotLinesAndBands[ 0 ].label;
if ( !!labelBackground ) {
labelBackground.attr({ y: textbox.y - 10 });
} else {
var box = textbox.getBBox();
labelBackground = crt.renderer.rect( box.x - 3, box.y + 1, box.width + 6, box.height, 3 ).attr( {
fill: '#fff',
id: 'labelBack',
opacity: .65,
'stroke-width': 0,
zIndex: 4
}).add();
}
}
}
I make sure this function is executed immediately after the chart is initialized and additionally I attach the function to the chart object that is returned from the StockChart call:
var chartObj = new Highcharts.StockChart( chartConfig, function ( crt ) {
labelDrawBack( crt );
} );
chartObj.labelDraw = labelDrawBack;
And in the chart options I have added this to the chart.redraw event:
events: {
redraw: function() {
this.labelDraw(this);
}
}
This works as intended, moving the transparent background with the label (which is moved vertically when the chart is resized).
The reason I have redirected the call in the chart redraw event is that the labelDrawBack function is defined in another function than the one where my chart options are defined, thus the labelDrawBack function is out of scope there.
I need to add a background image to the container div of highcharts
I think that this will meet your needs: http://jsfiddle.net/RYvcJ/2/.
Simply set transparent color for entire chart and use CSS.
just set this in chart of highcharts object ,
and set the x,y position and width and height of image , according to requirement
events: {
load: function() {
this.renderer.image('img/SqueezeBallEggOran500.jpg', -28, -5, 345, 301).add(); // add image(url, x, y, w, h)
}
}