score:1
I think the tutorial has dropped some code because we can't show JavaFX controls
such as Label
without adding it to a javafx.​scene.Parent
and the code didn't add it so how it can be shown!!
Here's the same code where we added the Label
to a Tooltip
and show the Tooltip
itself which contains the Label
final Label caption = new Label("");
caption.setTextFill(Color.DARKORANGE);
caption.setStyle("-fx-font: 24 arial;");
Tooltip container = new Tooltip();
container.setGraphic(caption);
for (final PieChart.Data data : chart.getData())
{
data.getNode().addEventHandler(MouseEvent.MOUSE_ENTERED,
new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent e)
{
if (container.isShowing())
{
container.hide();
}
caption.setText(String.valueOf(data.getPieValue()) + "%");
container.show(stage, e.getScreenX(), e.getScreenY());
}
});
}
It's preferred to use Java 8 Lambda Expressions and Streams so the code will be
final Label caption = new Label("");
caption.setTextFill(Color.DARKORANGE);
caption.setStyle("-fx-font: 24 arial;");
Tooltip container = new Tooltip();
container.setGraphic(caption);
chart.getData().forEach((data) ->
{
data.getNode().
addEventHandler(MouseEvent.MOUSE_ENTERED, e ->
{
if (container.isShowing())
{
container.hide();
}
caption.setText(String.valueOf(data.getPieValue()) + "%");
container.show(stage, e.getScreenX(), e.getScreenY());
});
});
Hope this is useful
Source: stackoverflow.com
Related Query
- JavaFx: Processing Events for a Pie Chart
- Highcharts display label for pie chart using html table as data source
- Highcharts not displaying data labels for Pie chart in arabic
- highcharts - chart names for multiple pie chart series in one chart
- HighCharts - Pie chart drilldown for multilevel (3 to 4 level)
- Highcharts - Display legend for Pie chart in two columns
- Write JSON parser to format data for pie chart (HighCharts)
- Highcharts:add click event on data label for pie chart
- Highcharts - where to place style and changing style for one wedge in a pie chart
- Pie Chart for Data on Different Things with HighChart
- highcharts pie chart color for dynamic data
- Custom CSS classes for Data Labels in Donut Pie Chart
- How to add different click events on each pie of a pie chart created by highcharts usin jquery
- Create Pie chart for each Json object
- Clickable Pie chart to select data for bar chart
- Gson to get Json value for a pie chart using Highcharts
- Highcharts how to make a set number of colors for pie chart data and drilldown data
- Highcharts to populate data for pie chart using json object
- Pie chart -custom event for legendItemClick-highchart
- Set Color for Pie Chart using HighChart + JSON data
- Highchart not showing 0 data correctly for pie chart
- how remove picture frame for Highchart chart pie
- Manipulate PHP array to group small values for use in Pie Chart
- highcharts shows exception "c is undefined" for pie chart
- How to add negative area or background for a specific bar or pie chart in highcharts?
- Highcharts - How to combine unique legend for multi-series pie chart which perform same action for both series? (like onclick: show/hide)
- Pie chart data labels are hidden for smaller values
- Highcharts - Pie chart Color for each slice
- How to display custom text for a specific category in pie chart tool tip
- How to set pie chart wedge colors based on wedge values for highcharts?
More Query from same tag
- How to display tooltips or legends on plotBands?
- highcharts zoom bug (column chart)
- How to position axis label in highcharts
- Synchronize two highcharts to drill down at once
- get yAxis labels as 10% of the categories of xAxis
- Multiple Highcharts on a PDF page - SVG Page Layout
- highchart's line chart with constant series not plotting when using linear gradient colour
- HighCharts pointPlacement option not working in a single column chart
- iOS Integrating highcharts
- why its difficult to set point padding and placement dynamically according to the data in fixed column chart (highcharts)?
- How to prevent bars overlapping eachother in Highcharts?
- Highcharts Pie, slice first item in series
- Highcharts - append % to first axis label?
- Highcharts userOptions does not update after changing the chart title
- Arrows only for rangeSelector in HighCharts
- Highchart doesn't display selected data properly
- Adding Default values to x Axis
- Template helper not ready even though it should be
- Google spreadsheet sharing
- Move label above bar
- Highcharts grouped column labels
- trying to use highchart xrange to display large number of categories
- how to use highcharts on ABP.NET angularjs
- Custom YTD Option in HighStock Range Selector
- array and object handling in javascript for getting highchart json data
- ionic 2 Uncaught (in promise): Error: Highcharts error #17: www.highcharts.com/errors/17
- Highchart Legend's Border
- How to modify highstock chart so that it can be used for displaying ranks (Lowest values on highest points)
- Highcharts css styles when exporting
- Highcharts pie chart size doesn't fill smaller containers even with dataLabels disabled