I've create a line chart with chart.js. I changed the legend symbol form from rects to circles by using:
legend: {
display: true,
labels: {
usePointStyle: true,
},
}
I want to change the size of the circles. But according to the documentation this is only possible if I also change the font size:
Label style will match corresponding point style (size is based on fontSize, boxWidth is not used in this case).
- https://www.chartjs.org/docs/latest/configuration/legend.html#legend-label-configuration
Does anyone know if there is another option to change the size? Or do I have to use generateLabels().
Here is a codePen to take a look on that.
You can use the boxWidth option to influence the size of the point in the legend:
options: {
legend: {
labels: {
usePointStyle: true,
boxWidth: 6
}
}
}
read the documentation of chartjs about legend
Related
I used area range Highcharts but facing certain issues as:
For X-axis, the chart doesn't start with an initial point rather shows incorrect start tick value(i.e. 2020) instead of 2019.
Need to show label values for last data point only for each series, attached image below for reference
Could someone please help me with what do I do to resolve my issues.
Thanks in advance!
For the 1st issue, I tried changing the 'pointStart' attribute value for plotOptions->series but didn't work.
"plotOptions": {
"series": {
"pointStart": 1546300800000
}
}
Here is JSFiddle link of the chart containing code:
The first issue can be resolved by setting xAxsi.tickInterval = plotOptions.series.pointInterval:
xAxis: {
type: "datetime",
tickInterval: 31536000000
...
}
The second issue can be resolved by providing labels formatter callback function that will return only the last series point value. Also, other dataLabels properties have to be set properly (like align, overflow, etc). Check demo and code posted below.
Code:
dataLabels: {
enabled: true,
align: 'left',
verticalAlign: 'middle',
padding: 8,
allowOverlap: true,
overflow: 'allow',
crop: false,
formatter: function() {
var point = this.point,
series = this.series;
if (series.data.length === point.index + 1) {
return '$' + this.y.toFixed(1);
} else {
return '';
}
}
}
Demo:
https://jsfiddle.net/BlackLabel/2xLevj6y/
API reference:
https://api.highcharts.com/highcharts/xAxis.tickInterval
https://api.highcharts.com/class-reference/Highcharts.DataLabelsOptionsObject#formatter
https://api.highcharts.com/class-reference/Highcharts.DataLabelsOptionsObject#align
https://api.highcharts.com/class-reference/Highcharts.DataLabelsOptionsObject#overflow
For my graph, I have a single y-axis (y1), and I am trying to add a second axis (y2) which is a scaled version of y1.
Simply put, is it possible to do a graph like this. But I want a second axis, with the same scaling ratio, but in different units (i.e. that is multiplied by some k).
I have tried to just change the label on the yAxis:
` labels: {
format: '$ {value* price} ',
style: {
color: Highcharts.getOptions().colors[0]
}
},`
But this hacky way does not seem to work for me.
In my case, I have a graph of percent change on y1, is it possible to put the price on y2?
I do not want to add another set of lines since I am already using 10, which would mean I would need 20 lines in total
Any help would be greatly appreciated!
You need to link the second axis to the first by linkedTo property and use formatter function to display some custom scale:
yAxis: [{}, {
opposite: true,
labels: {
formatter: function() {
return this.value * 1000
}
},
linkedTo: 0
}]
Live demo: http://jsfiddle.net/BlackLabel/j83pghta/
API Reference:
https://api.highcharts.com/highcharts/yAxis.linkedTo
https://api.highcharts.com/highcharts/yAxis.labels.formatter
I am trying to add multiple lines in the tooltip for my horizontal stacked bar chart but the last couple lines are getting cut off by the end of the chart canvas. Is it possible to make the tooltip extend over the end of the chart canvas?
tooltips: {
mode: 'nearest',
intersect: true,
callbacks: {
footer: function() {
var withBreaks = "Hello World. \n My name is Jennifer. \n What is your name?"
return withBreaks;
},
}
},
Either you can add bottom padding to your canvas
options: {
layout: {
padding: {
bottom: 25 //set that fits the best
}
},
}
Another option is to set the yAlign of tooltip to center, so the tooltip won't occupy the bottom space of the canvas.
options: {
tooltips: {
yAlign: 'center'
}
}
Please have a look at this issue, especially https://github.com/chartjs/Chart.js/issues/622#issuecomment-72480781 comment.
A similar problem was faced here too.
Is there a way to adjust the line-height of axis labels in Highcharts? Sometimes with line-broken labels, overlap/spacing issues can occur that would be mitigated if it were possible to decrease line-height.
As you can see in the longer red labels in the image below, it would be helpful to customize line-height. Is there a way to do this? Setting line-height in either the CSS or in xAxis.labels.style did not have any effect.
Example options:
xAxis: {
labels: {
style: {
textOverflow: 'none', // To disable automatic ellipsizing, per https://github.com/highcharts/highcharts/issues/3941
// lineHeight: '0.5' // Has no effect
}
},
categories: [
'Sweden',
'Federal Democratic Republic of Ethiopia',
'Finland',
'United Kingdom of Great Britain and Northern Ireland',
'Oceania'],
...
Codepen: http://codepen.io/ericpedia/pen/peNZML
You cannot do this via css because there is no line-height presentational attribute support in svg. See the answer svg-how-to-set-text-line-height. What Highcharts do - it mocks html-css line-height property on svg by setting dy property. In SVG dy is not a presentational attribute so it cannot be set in stylesheet.
To preserve the lineheight option, you can modify Highcharts internal method so its cssish style will be applied.
var H = Highcharts;
H.wrap(H.Tick.prototype, 'addLabel', function (p) {
p.call(this);
const label = this.label;
const labelOptions = this.axis.options.labels;
if (label) {
label.css({
lineHeight: labelOptions.style.lineHeight
})
}
})
Axis config:
labels: {
style: {
textOverflow: 'none',
lineHeight: 12
}
},
Live example and output:
https://jsfiddle.net/4dztcw5d/
As I mentioned in the comment, you can also set labels.useHTML to true, build a proper html and apply to it html-css styling, including line-height.
For some reason the highcharts library that you are using doesn't take into account some of the css.
I tried using this one http://code.highcharts.com/highcharts.js and seems to work i added in the x-axis label style
fontSize:'15px',
lineHeight: "12"
and had to set the colors with !important
text:nth-child(odd){ fill: blue!important; }
text:nth-child(even){ fill: red!important; }
and it seems to work, here is the codepen http://codepen.io/anon/pen/ryWoxo
I have no idea how I can change the circle size.
In my chart, the circle is very small.
I want a bigger circle than it is currently.
code ex :
plot2 = jQuery.jqplot('PieChart',[ ticks ,rs_money],
{
grid: {
drawBorder: false,
drawGridlines: false,
background: 'transparent',
shadow:false
},
axesDefaults: {
},
seriesDefaults:{
renderer:$.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true,
startAngle: 180,
sliceMargin: 2
}
},
legend: { fontSize:'11px',show:true,location: 's', labels:ticks}
}
I alter the size of the circle via CSS. The pie itself is set up to shrink or grow with the div, as long as it isn't too small. Try styling the div with width and height to see if that is what you're looking for.
<div id="pieChart" style="width:50%;height:50%;"></div>
You can also go into the jqplot.pieRenderer.js and look for
this.diameter=null;this.padding=20;
The null value can be changed to any number you like to make the circle bigger. If you make it bigger than your div though, it will stretch out of the div's bounds. You can also change the padding to have the circle take up more space in the div.
Check out their documentation:
http://www.jqplot.com/docs/files/jqPlotOptions-txt.html
seriesDefaults: {
rendererOptions: {
diameter: <your value>, // diameter of pie, auto computed by default.
table.jqplot-table-legend {
table-layout: fixed;
}
td.jqplot-table-legend-label
{
max-width:100px;
}
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
padding: 10
}
}
You can reduce the space by using padding option.By changing padding you can change the size of pie chart.