Skip to content

Pie chart #84

@markov00

Description

@markov00

Is your feature request related to a problem? Please describe.
It's required to draw piechart and donut chart, with one or multiple levels.

Describe the solution you'd like

  • Reuse as much as possible the code already implemented for XY axis
  • Use the same Chart structure but different specs for chart PieChartSeries

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Rendering a piechart is not so difficult, we can just use d3-arcs to compute the paths.

import { arc, pie } from 'd3-shape';

const pieSpec = {
  data: [[10],[20], [30]],
  accessor: 0,
}

const paths = pie().value((d: any) => {
  return d[pieSpec.accessor];
})(pieSpec.data);

// that is the space allowed to render the pie chart we should take in consideration the 
// how much space a direct labelling on the chart take
const { width, height } = chartDimensions; 
const outerRadius = width < height ? width / 2 : height / 2;
const innerRadius = pieSpec.donut ? outerRadius / 2 : 0;

const arcGenerator = arc();
const arcs = paths.map((path) => {
  const arc = arcGenerator({
    ...path,
    innerRadius: innerRadius,
    outerRadius: outerRadius,
  });
  return {
    arc: arc === null ? '' : arc,
    color: 'red',
    transform: {
      x: width / 2,
      y: height / 2,
    },
    geometryId: {
      specId: pieSpec.id,
      seriesKey: [],
    },
    seriesArcStyle: settings.theme.arcSeriesStyle.arc,
  };
});

The difficult part is the label positioning, place labels to avoid overlaps and overflows.
The pre-computing label dimensions will came in handy, but we need a good alghoritm to place them without overlapping them together.

We have to take in consideration also the style of the slices, specially when we will have many small slices.

Consider also label rotations as described here: https://www.amcharts.com/docs/v4/tutorials/labels-inside-pie-chart-slices/

Other interesting references:

Features:

Kibana Cross Issues

Checklist

  • this request is checked against already exist requests
  • every related Kibana issue is listed under Kibana Cross Issues list
  • kibana cross issue tag is associated to the issue if any kibana cross issue is present

Metadata

Metadata

Assignees

Labels

:new chart typeNew chart type related feature requestenhancementNew feature or requestkibana cross issueHas a Kibana issue counterpartreleasedIssue released publicly

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions