I am trying to create a pie chart of size 320 x 320 px as shown below:
When a pie is selected, it should expand like this:
What I have been able to achieve so far is shown below, which is obviously too far from the spirit of the design. I am not sure what levers to pull to get as close as possible to the requirements. Please see my CodeSandbox here.
The high-level requirements are:
Chart size: 320 x 320 px
Donut diameter: 152px
Font family: Overpass
Font sizes:
General: 12px
Title: 16px
Total count: 32px
Some questions I have:
How to reduce the size of the "ticks" so that the ellipsis on category labels are avoided. Or is there a way to wrap the category labels to avoid the ellipsis?
How to add the data value to each spending category?
How to add the total value in the middle?
How to control font sizes on each element?
How to grow a pie when selected?
How to suppress the animations on hover?
My implementation so far is here.
Update
After further research and incorporating changes suggested by #Sebastian Wędzel, I have been able to bring the implementation upto the following level:
I see that you already found most of the answers to your questions. Here are my proposals for unanswered questions:
Chart size: 320 x 320 px - you can define the chart.width and chart.height
API: https://api.highcharts.com/highcharts/chart.width
How to add the total value in the middle?
You can render it as a custom text by using the SVGRenderer tool.
Demo: https://jsfiddle.net/BlackLabel/xbhas3g6/
API: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#text
How to grow a pie when selected?
Here you probably will need to change your series type to the variablepie - demo: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/variable-radius-pie and implement the point.update on the click event to increase selected point Z value.
API: https://api.highcharts.com/highcharts/series.variablepie.point.events.click
API: https://api.highcharts.com/class-reference/Highcharts.Point#update
Related
Hello to the community,
I would have one more question on Highcharts. I am working closely with designers and they prefer to have charts given to them with a predefined height, width, and text size, in millimetres (not pixels). That is because ultimately these charts are going to be printed out in reports.
Right now designers enter the value they want for a specific chart in millimetres onto a spreadsheet, and I convert all that to px before making the chart.
To convert pixel to mm I use:
px = mm * DPI / 25.4 since 1in = 25.4 mm.
For point (pt) to pixel I use:
px = pt * DPI/72 since 1pt = 1/72th of 1in.
Where DPI is a variable given to me: usually 300.
However the font size tends to be much bigger than it should be (it looks like it is 20 pt on the chart when I want 12 pt), and the chart dimensions also seem to be wrong.
My first question: do my calculations look right? (I am afraid I am not much of an image expert).
My second question: would there be a way to specify chart dimensions in a different format than pixel when configuring a chart on Highcharts, by any chance?
Thank you so very much!
You can use some of the already existing converters to get those values, like: https://www.unitconverters.net/typography/millimeter-to-pixel-x.htm
You can use CSS to set parameters for the container that the chart is rendered inside, demo: https://jsfiddle.net/BlackLabel/vu41gdt6/
#container {
height: 15rem;
width: 15rem;
}
Consider use regular CSS units for the charts on you web app and change them only for printing needs.
API: https://api.highcharts.com/highcharts/chart.events.beforePrint
Useful article: Using cm/mm on the CSS of a web app that replicates paper interaction is a good practice?
I have three pie charts displayed in a row. Two have two segments, one has five. All three have vertical legends.
Given that, the chart with five segments displays the pie slightly smaller, due to the extra height of the legend. It also has a slight negative vertical offset.
Is there any way I can set all three charts to render the chart in the same position? I've tried setting the center to 50%,50% in plotOptions, didn't help.
You have to set the marginBottom-Value of the chart to a value that is equal an all charts. Highcharts is trying to display the pie as big as possible, therefore it will use more space if the legend is not as big.
By setting the marginBottom you force the chart to ignore the actual legend size.
The center: ['50%','50%'] setting will only take into account the actual plot area. So if this area is decreased because of a taller legend it has no effect.
I made a jsfiddle where you can explore this settings:
http://jsfiddle.net/doc_snyder/dsmgy6ts/
Highcharts columns sometimes don't make proper use of the available height, in some cases leaving nearly the upper half of a chart empty. After fiddling with the official example charts I noticed that the y-axis max extreme (internally) seems to be dependent on the chart's container height.
For example, the Highcharts example for stacked column chart:
The original example (container height of 400px) has a max of 12.5 for the y-axis with the largest columns having a value of 11. ~90% of the chart height are used.
When modifying the height to 300px, y-axis max changes to 15, so that only ~75% of the height is used.
When modifying the height to 200px, y-axis max changes to 20, only ~55% of the height being used.
Is there a way to improve this behavior without programmatically setting the axis extremes whenever the displayed data changes? You might argue that applying such a small height to a column chart is a weird thing to do, but this is just an example, I have seen similar behavior with larger charts (having other data).
This is related with fact, that defaulty highcharts has enabled maxPadding. Set that parameter as 0 to fillout area more efficient.
yAxis: {
maxPadding:0
}
The example charts could be fixed with Sebastian's answer. After applying the change to my own chart, I noticed another problem that screwed up the scale even more, but was not part of this question - adding this as another answer, just for the sake of completeness.
My chart consisted of combined column/line chart with a 2nd y-axis. Depending on its values, the line chart series had strange effects on the scale of the columns (even if the line chart series was empty). Doing some more research I found this SO answer pointing me to Highcharts' alignTicks option, setting it to false resolved the issue.
We recently made the switch from JFreeCharts to Highcharts. And our apps teams build small pie charts (fit in 250 by 400 px) on a dashboard, that usually show less than 8 slices. The pie labels are verbose. Highcharts usually clips them off is what I am seeing.
JSFiddle: jsfiddle.net/9tqSn/18/
It is close to what we see on our system even with word wrapping and such. Our customers also hate the fact that the chart size shrinks when labels are long. Do you plan to have a solution to better fit labels in the plot area?
We are running highcharts-3.0.2
Well, this is known bug in Highcharts, see this report.
Here you can find discussion about positioning dataLabels.
This functionality is available for the Pie Chart via the plotOptions size parameter, however after inspecting the Highcharts API the size isn't available for the Gauge.
size API entry for Pie Chart
Considering the likeness of the two charts (being circular), I was hoping there would be a similar option but the gauge always fills some subset of the container div that I am unable to control. Has anyone else run into this issue or found a solution?
By setting the spacing to zero, you can fill the entire space:
http://jsfiddle.net/mkremer90/3sngK/1/
Fiddle with the spacing parameters to change how much the chart fills. As for a percentage based like size option I can't find one either.
I know this is old, but if like me, you have borderWidth set to something greater than 0, you'll find yourself with the tag being positioned (e.g. x="5.5" y="5.5") off from the corner and width and height shrunk. Setting spacing and margin options won't help in this case.
The simple solution then is to avoid setting borderWidth to anything at all; just leave it default or set it to zero. Instead, set the border on the container element you're calling highcharts on.
Alternatively, you could set negative margins and increase size on the container element to compensate for position shift and size shrink on the graph. Might need to wrap the container in a div with style="overflow: hidden;".