Draw charts from Azure Data Explorer queries
Перейти к файлу
Violet Voronetzky 3ebf3a1c45 Added chart title option and handle container resize 2019-12-04 15:52:34 +02:00
.vscode Initial release 2019-11-10 18:08:31 +02:00
definitelyTyped Initial release 2019-11-10 18:08:31 +02:00
src Added chart title option and handle container resize 2019-12-04 15:52:34 +02:00
test Added theme support 2019-12-03 18:28:51 +02:00
.gitignore Initial release 2019-11-10 18:08:31 +02:00
.travis.yml Add Travis + badge 2019-11-11 09:06:59 +02:00
CODE_OF_CONDUCT.md Update to MS Code Of Conduct + MIT lisence 2019-11-11 14:45:49 +02:00
LICENSE Updating LICENSE to template content 2019-11-10 07:38:22 -08:00
README.md Added chart title option and handle container resize 2019-12-04 15:52:34 +02:00
SECURITY.md Initial SECURITY.md commit 2019-11-10 07:38:25 -08:00
index.ts Added highcharts visualizer and data transformations 2019-12-01 10:19:14 +02:00
launch.json Initial release 2019-11-10 18:08:31 +02:00
package-lock.json Fixed comment 2019-12-02 10:46:51 +02:00
package.json Fixed comment 2019-12-02 10:46:51 +02:00
tasks.json Initial release 2019-11-10 18:08:31 +02:00
tsconfig.json Initial release 2019-11-10 18:08:31 +02:00

README.md

This package is a work in process. Please DO NOT USE it yet

adx-query-charts

Build Status    npm version

Draw charts from Azure Data Explorer queries

Installation

npm install adx-query-charts

Dependencies

Make sure to install the following packages before using the adx-query-charts library:

  1. moment: npm i moment
  2. lodash: npm i lodash
  3. highcharts: npm i highcharts

Usage

import * as Charts from 'adx-query-charts';

const highchartsVisualizer = new Charts.HighchartsVisualizer();
const chartHelper = chartHelper = new Charts.KustoChartHelper('chart-elem-id', highchartsVisualizer);
const chartOptions: Charts.IChartOptions = {
    chartType: Charts.ChartType.UnstackedColumn,
    columnsSelection: {
        xAxis: { name: 'timestamp', type: Charts.DraftColumnType.DateTime },
        yAxes: [{ name: 'requestCount', type: Charts.DraftColumnType.Int }]
    }
};

// Draw the chart - the chart will be drawn inside an element with 'chart-elem-id' id
chartHelper.draw(queryResultData, chartOptions);

API

KustoChartHelper

Method: Description: Input: Return value:
draw Draw the chart IQueryResultData - The original query result data
IChartOptions - The information required to draw the chart
void
changeTheme Change the theme of an existing chart ChartTheme - The theme to apply void
getSupportedColumnTypes Get the supported column types for the axes and the split-by
for a specific chart type
ChartType - The type of the chart ISupportedColumnTypes
getSupportedColumnsInResult Get the supported columns from the query result data for the axes and the split-by for a specific chart type IQueryResultData - The original query result data
ChartType - The type of the chart
ISupportedColumns
getDefaultSelection Get the default columns selection from the query result data.
Select the default columns for the axes and the split-by for drawing a default chart of a specific chart type.
IQueryResultData - The original query result data
ChartType - The type of the chart
ISupportedColumns - (Optional) The list of the supported column types for the axes and the split-by
IColumnsSelection

IChartOptions

Option name: Type: Details: Default value:
chartType ChartType Mandatory.
The type of the chart to draw
columnsSelection IColumnsSelection The columns selection for the Axes and the split-by of the chart If not provided, default columns will be selected.
See: getDefaultSelection method
maxUniqueXValues number The maximum number of the unique X-axis values.
The chart will show the biggest values, and the rest will be aggregated to a separate data point.
100
exceedMaxDataPointLabel string The label of the data point that contains the aggregated value of all the X-axis values that exceed the 'maxUniqueXValues'. 'OTHER'
aggregationType AggregationType Multiple rows with the same values for the X-axis and the split-by will be aggregated using a function of this type.
For example, assume we get the following query result data:
['2016-08-02T10:00:00Z', 'Chrome 51.0', 15],
['2016-08-02T10:00:00Z', 'Internet Explorer 9.0', 4]
When drawing a chart with columnsSelection = { xAxis: timestamp, yAxes: count_ }, and aggregationType = AggregationType.Sum we need to aggregate the values of the same timestamp value and return one row with ["2016-08-02T10:00:00Z", 19]
AggregationType.Sum
title string The title of the chart
utcOffset number The desired offset from UTC in hours for date values. Used to handle timezone.
The offset will be added to the original date from the query results data.
For example:
For 'Africa/Harare'timezone provide utcOffset = 2 and the displayed date will be be:
'11/25/2019, 2:00 AM' instead of '11/25/2019, 12:00 AM'
See time zone [info](https://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11)
0
chartTheme ChartTheme The theme of the chart ChartTheme.Light

ChartType

enum ChartType {
    Line,
    Scatter,
    UnstackedArea,
    StackedArea,
    PercentageArea,
    UnstackedColumn,
    StackedColumn,
    PercentageColumn,
    Pie,
    Donut,
}

IColumnsSelection

interface IColumn {
    name: string;
    type: DraftColumnType;
}

interface IColumnsSelection {
    xAxis: IColumn;
    yAxes: IColumn[];
    splitBy?: IColumn[];
}

AggregationType

enum AggregationType {
    Sum,
    Average,
    Min,
    Max
}

ChartTheme

enum ChartTheme {
    Dark,
    Light
}

IColumn

type IRowValue = string | number;
type ISeriesRowValue = IRowValue | string[] | number[];
type IRow = IRowValue[];
type ISeriesRow = ISeriesRowValue[];

interface IColumn {
    name: string;
    type: DraftColumnType;
}

IQueryResultData

interface IQueryResultData {
    rows: IRow[] | ISeriesRow[];
    columns: IColumn[];
}

See IColumn

ISupportedColumns

interface ISupportedColumns {
    xAxis: IColumn[];
    yAxis: IColumn[];
    splitBy: IColumn[];
}

See IColumn

DraftColumnType

See: https://kusto.azurewebsites.net/docs/query/scalar-data-types/index.html

enum DraftColumnType {
    Bool,
    DateTime,
    Decimal,
    Dynamic,
    Guid,
    Int,
    Long,
    Real,
    String,
    TimeSpan
}

ISupportedColumnTypes

interface ISupportedColumnTypes {
    xAxis: DraftColumnType[];
    yAxis: DraftColumnType[];
    splitBy: DraftColumnType[];
}

See DraftColumnType

Test

Unit tests are written using Jest.

Run tests: npm run test

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.