How to use @elastic/charts - 10 common examples

To help you get started, we’ve selected a few @elastic/charts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / infra / public / pages / logs / analysis / sections / anomalies / chart.tsx View on Github external
});
    },
    [setTimeRange]
  );

  return (
    <div style="{{">
      
        
         numeral(value.toPrecision(3)).format('0[.][00]a')} // https://github.com/adamwdraper/Numeral-js/issues/194
        /&gt;
        
        {renderAnnotations(annotations, chartId, renderAnnotationTooltip)}</div>
github elastic / kibana / x-pack / legacy / plugins / uptime / public / components / functional / charts / duration_chart.tsx View on Github external
export const DurationChart = ({
  locationDurationLines,
  meanColor,
  rangeColor,
}: DurationChartProps) =&gt; {
  const { absoluteStartDate, absoluteEndDate } = useContext(UptimeSettingsContext);
  // this id is used for the line chart representing the average duration length
  const averageSpecId = getSpecId('average-');

  const lineSeries = locationDurationLines.map(line =&gt; {
    const locationSpecId = getSpecId('loc-avg' + line.name);
    return (
       [x || 0, microsToMillis(y)])}
        id={locationSpecId}
        key={`locline-${line.name}`}
        name={line.name}
        xAccessor={0}
        xScaleType={ScaleType.Time}
        yAccessors={[1]}
        yScaleToDataExtent={false}
        yScaleType={ScaleType.Linear}
github elastic / kibana / x-pack / legacy / plugins / lens / public / xy_visualization_plugin / to_expression.ts View on Github external
export function getScaleType(metadata: OperationMetadata | null, defaultScale: ScaleType) {
  if (!metadata) {
    return defaultScale;
  }

  // use scale information if available
  if (metadata.scale === 'ordinal') {
    return ScaleType.Ordinal;
  }
  if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
    return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
  }

  // fall back to data type if necessary
  switch (metadata.dataType) {
    case 'boolean':
    case 'string':
      return ScaleType.Ordinal;
    case 'date':
      return ScaleType.Time;
    default:
      return ScaleType.Linear;
  }
}
github elastic / kibana / x-pack / legacy / plugins / lens / public / xy_visualization_plugin / to_expression.ts View on Github external
// use scale information if available
  if (metadata.scale === 'ordinal') {
    return ScaleType.Ordinal;
  }
  if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
    return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
  }

  // fall back to data type if necessary
  switch (metadata.dataType) {
    case 'boolean':
    case 'string':
      return ScaleType.Ordinal;
    case 'date':
      return ScaleType.Time;
    default:
      return ScaleType.Linear;
  }
}
github elastic / kibana / x-pack / legacy / plugins / ml / public / jobs / new_job / pages / components / charts / common / axes.tsx View on Github external
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import React, { FC, Fragment } from 'react';
import { Axis, getAxisId, Position, timeFormatter, niceTimeFormatByDay } from '@elastic/charts';
import { getYRange } from './utils';
import { LineChartPoint } from '../../../../common/chart_loader';

const dateFormatter = timeFormatter(niceTimeFormatByDay(3));

interface Props {
  chartData?: LineChartPoint[];
}

// round to 2dp
function tickFormatter(d: number): string {
  return (Math.round(d * 100) / 100).toString();
}

export const Axes: FC = ({ chartData }) =&gt; {
  const yDomain = chartData !== undefined ? getYRange(chartData) : undefined;

  return (
github elastic / kibana / x-pack / legacy / plugins / lens / public / xy_visualization_plugin / to_expression.ts View on Github external
return defaultScale;
  }

  // use scale information if available
  if (metadata.scale === 'ordinal') {
    return ScaleType.Ordinal;
  }
  if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
    return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
  }

  // fall back to data type if necessary
  switch (metadata.dataType) {
    case 'boolean':
    case 'string':
      return ScaleType.Ordinal;
    case 'date':
      return ScaleType.Time;
    default:
      return ScaleType.Linear;
  }
}
github elastic / kibana / x-pack / legacy / plugins / lens / public / xy_visualization_plugin / to_expression.ts View on Github external
export function getScaleType(metadata: OperationMetadata | null, defaultScale: ScaleType) {
  if (!metadata) {
    return defaultScale;
  }

  // use scale information if available
  if (metadata.scale === 'ordinal') {
    return ScaleType.Ordinal;
  }
  if (metadata.scale === 'interval' || metadata.scale === 'ratio') {
    return metadata.dataType === 'date' ? ScaleType.Time : ScaleType.Linear;
  }

  // fall back to data type if necessary
  switch (metadata.dataType) {
    case 'boolean':
    case 'string':
      return ScaleType.Ordinal;
    case 'date':
      return ScaleType.Time;
    default:
      return ScaleType.Linear;
  }
}
github elastic / kibana / x-pack / legacy / plugins / lens / public / xy_visualization_plugin / xy_suggestions.ts View on Github external
xValue: TableSuggestionColumn;
  splitBy: TableSuggestionColumn | undefined;
  layerId: string;
  changeType: TableChangeType;
}) {
  const newLayer = {
    ...(getExistingLayer(currentState, layerId) || {}),
    layerId,
    seriesType,
    xAccessor: xValue.columnId,
    splitAccessor: splitBy ? splitBy.columnId : generateId(),
    accessors: yValues.map(col => col.columnId),
  };

  const state: State = {
    legend: currentState ? currentState.legend : { isVisible: true, position: Position.Right },
    preferredSeriesType: seriesType,
    layers: [
      ...(currentState ? currentState.layers.filter(layer => layer.layerId !== layerId) : []),
      newLayer,
    ],
  };

  return {
    title,
    score: getScore(yValues, splitBy, changeType),
    // don't advertise chart of same type but with less data
    hide: currentState && changeType === 'reduced',
    state,
    previewIcon: getIconForSeries(seriesType),
  };
}
github elastic / kibana / x-pack / legacy / plugins / ml / public / jobs / new_job / pages / components / charts / common / axes.tsx View on Github external
export const Axes: FC = ({ chartData }) =&gt; {
  const yDomain = chartData !== undefined ? getYRange(chartData) : undefined;

  return (
    
      
      
    
  );
};