A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://js.devexpress.com/Vue/Documentation/Guide/UI_Components/PivotGrid/Integration_with_Chart/ below:

Vue PivotGrid - Integration with Chart

Vue PivotGrid - Integration with Chart

PivotGrid handles large numeric datasets that can be difficult to interpret. For more detailed data visualization, use the Chart component. To link PivotGrid with Chart, call the bindChart(chart, integrationOptions) method. This article explores the features of this method.

View Demo

Bind the Chart

PivotGrid can be bound only to an existing Chart.

For example, the following code creates a PivotGrid component and a Chart component:

jQuery
<div id="pivot-grid"></div>
<div id="chart"></div>
$(function () {
    $("#pivot-grid").dxPivotGrid({ ... });
    $("#chart").dxChart({ ... });
});
Angular
<dx-pivot-grid></dx-pivot-grid>
<dx-chart></dx-chart>
Vue
<template>
    <DxPivotGrid />
    <DxChart />
</template>
<script setup lang="ts">
import DxPivotGrid from 'devextreme-vue/pivot-grid';
import DxChart from 'devextreme-vue/chart';
</script>
React
import React from 'react';
import PivotGrid from 'devextreme-react/pivot-grid';

const App = () => {
    return (
        <React.Fragment>
            <PivotGrid />
            <Chart />
        </React.Fragment>
    );
}

export default App;

To bind Chart and PivotGrid without changing the default integration properties, call bindChart(chart, integrationOptions). This method can be called at any point of the application flow. For example, you can bind the chart once it is initialized:

jQuery
$(function () {
    $("#pivot-grid").dxPivotGrid({ ... });
    $("#chart").dxChart({
        // ...
        onInitialized: function (e) {
            var pivotGridInstance = $("#pivot-grid").dxPivotGrid("instance");
            pivotGridInstance.bindChart('#chart');
        }
    });
});
Angular
// ...
export class AppComponent implements AfterViewInit {
    @ViewChild(DxPivotGridComponent, { static: false }) pivotGrid: DxPivotGridComponent;
    @ViewChild(DxChartComponent, { static: false }) chart: DxChartComponent;

    ngAfterViewInit() {
        this.pivotGrid.instance.bindChart(this.chart.instance);
    }
}
Vue
<template>
    <DxPivotGrid ref="grid" />
    <DxChart ref="chart" />
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
// ...
const grid = ref<DxPivotGrid>();
const chart = ref<DxChart>();

onMounted(() => {
    grid.value?.instance?.bindChart(chart.value?.instance);
});
</script>
React
import React, { useEffect, useRef } from 'react';
// ...

const App = () => {
    const chartRef = useRef<ChartRef>(null);
    const pivotGridRef = useRef<PivotGridRef>(null);
    useEffect(() => {
        pivotGridRef.current.instance().bindChart(chartRef.current.instance());
    }, []);

    return (
        <React.Fragment>
            <PivotGrid ref={pivotGridRef} />
            <Chart ref={chartRef} />
        </React.Fragment>
    );
}

If the bindChart(chart, integrationOptions) method returns null, the binding failed.

See Also Convert Grid Fields into Chart Series

The second argument of the bindChart(chart, integrationOptions) method customizes the contents, behavior, and appearance of the Chart component. This section describes the fields in this argument that handle data procession.

When binding Chart to PivotGrid, specify how to form Chart series from PivotGrid fields. PivotGrid data fields always become Chart value fields. Row and column fields can form either arguments or series. The inverted field specifies the following values:

In the example below, toggle the check box to update the inverted field. When this field is false, values of the "2014" column field become the arguments, while values of the "Europe" row field form series. When inverted is true, the result is reversed.

When PivotGrid contains multiple data fields, they can become sets of series or sets of arguments. To specify this behavior, use the putDataFieldsInto field and choose "series" (default) or "args".

pivotGridInstance.bindChart(chartInstance, {
    // ...
    putDataFieldsInto: "series" // "args"
});

Some data fields may alternate on the Chart plot. To control this behavior, set the alternateDataFields field to true (default) or false.

pivotGridInstance.bindChart(chartInstance, {
    // ...
    alternateDataFields: true // false
});

Below, use the controls under the UI components to change the putDataFieldsInto and alternateDataFields fields. Observe how the "Total" and "Avg" data fields depend on these values.

To process data in a specific way, assign a callback function to the processCell field. This function will be called for each data cell of PivotGrid.

pivotGridInstance.bindChart(chartInstance, {
    // ...
    processCell: function (cellData) {
        // Process data here
        return cellData; // This line is optional
    }
});

The cellData argument has the following fields:

Customize the Chart

In the previous topic, you learned how to process data through the second argument of the bindChart(chart, integrationOptions) method. Subtopics in this section cover how to adjust the fields of this argument to modify the Chart appearance.

Customize the Series

If you need to customize the automatically-formed series, assign a callback function to the customizeSeries field. This function will be called once for each series.

pivotGridInstance.bindChart(chartInstance, {
    // ...
    customizeSeries: function (seriesName, seriesOptions) {
        // Change series properties here
        return seriesOptions; // This line is optional
    }
});

The function accepts the following arguments.

The seriesOptions can contain any appearance-related properties from the series section of the reference.

When series are generated from several data fields, they can be arranged in three different ways:

To specify the exact way, use the dataFieldsDisplayMode field.

pivotGridInstance.bindChart(chartInstance, {
    // ...
    dataFieldsDisplayMode: 'splitAxes' | 'singleAxis' | 'splitPanes'
});

NOTE

If you have set the

putDataFieldsInto

field to

"args"

,

dataFieldsDisplayMode

will be set to

"singleAxis"

forcedly.

Customize the Value Axes and Panes

To customize the automatically-generated value axes or panes, assign a callback function to the customizeChart field. This function will be called once - before rendering the Chart.

pivotGridInstance.bindChart(chartInstance, {
    // ...
    customizeChart: function (chartOptions) {
        // Change Chart properties here
        return chartOptions; // This line is optional
    }
});

The chartOptions object contains the following fields.

The customizeChart(chartOptions) function is designed mainly for customizing the automatically-generated Chart elements. However, the argument of this function accepts any property of Chart that configures the UI component's appearance. Alternatively, you can specify the properties when you design the Chart. They merge with the properties returned by the customizeChart(chartOptions) function.

Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4