elastic / elastic-charts

https://elastic.github.io/elastic-charts/storybook
Other
368 stars 116 forks source link

Value labels for line and area charts #797

Open wylieconlon opened 4 years ago

wylieconlon commented 4 years ago

I couldn't figure out what value labels were supposed to look like for line and area charts, so I've pulled some examples from popular chart-building tools:

Line charts:

Screen Shot 2020-08-27 at 2 13 29 PM Screen Shot 2020-08-27 at 2 17 59 PM

Area charts:

Screen Shot 2020-08-27 at 2 13 40 PM

Stacked area charts:

Screen Shot 2020-08-27 at 2 13 49 PM Screen Shot 2020-08-27 at 2 18 15 PM

dej611 commented 3 years ago

Actually this colored-labels label colored per category trick may be good also for bar charts

qbob1 commented 9 months ago

To anyone looking for a workaround on this issue: You can layer a line chart on top of some transparent bar charts with a small padding value:

theme: { ...defaultChartTheme, scales: { barsPadding: 1 } },
{yAccessors?.map((yAccessor, index) => (
            <LineSeries
              id={toTitleCase(yAccessor)}
              key={yAccessor}
              name={yLegendOverrides?.[index] ?? toTitleCase(yAccessor)}
              xScaleType={xAxisProps?.scaleType}
              yScaleType={yAxisProps?.scaleType}
              xAccessor={xAccessor}
              yAccessors={[yAccessor]}
              data={baseData ?? []}
            />
          ))}
          {yAccessors?.map((yAcc, i) => (
            <BarSeries
              id={yAcc}
              xScaleType={xAxisProps?.scaleType}
              yScaleType={yAxisProps?.scaleType}
              xAccessor={xAccessor}
              yAccessors={[yAcc]}
              filterSeriesInTooltip={() => false}
              data={baseData ?? []}
                showValueLabel: true,
                overflowConstraints: [],
              }}
              hideInLegend={true}
              styleAccessor={(datum, b) => {
                return {
                  rect: {
                    opacity: 0,
                  },
                };
              }}
            />
          ))}

labels