Vue Flexmonster Pivot Table & Charts

2.9.127 · active · verified Tue Apr 21

The `vue-flexmonster` package provides a robust wrapper for integrating the Flexmonster Pivot Table & Charts component into Vue 2 and Vue 3 applications. Flexmonster is a highly customizable JavaScript component designed for web reporting and data analysis, supporting a wide array of data sources including SQL/NoSQL databases, JSON, CSV, OLAP cubes, and Elasticsearch. The current stable version, 2.9.127, aligns with the core Flexmonster library. The Flexmonster ecosystem typically releases minor versions with bug fixes and enhancements biweekly, alongside major versions introducing significant features once or twice a year. Key differentiators include its extensive feature set for data manipulation, comprehensive data source connectivity, and dedicated, well-documented integrations for both Vue 2 and Vue 3, supported by responsive technical assistance.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to embed the Flexmonster Pivot component in a Vue 3 application using the Composition API. It initializes with inline JSON data, defines a basic slice, customizes cell styling based on data values, and shows how to access the underlying Flexmonster API.

<script setup lang="ts">
import { ref } from 'vue';
import { Pivot } from 'vue-flexmonster/vue3';
import 'flexmonster/flexmonster.css'; // Essential for styling

interface SalesData {
  Category: string;
  Price: number;
  Quantity: number;
}

const report = ref<Flexmonster.Report> ({
  dataSource: {
    data: [
      { Category: "Accessories", Price: 100, Quantity: 10 },
      { Category: "Bikes", Price: 200, Quantity: 5 },
      { Category: "Components", Price: 50, Quantity: 20 },
      { Category: "Accessories", Price: 120, Quantity: 8 },
      { Category: "Bikes", Price: 250, Quantity: 3 }
    ] as SalesData[]
  },
  slice: {
    rows: [{ uniqueName: "Category" }],
    columns: [{ uniqueName: "[Measures]" }],
    measures: [
      { uniqueName: "Price", aggregation: "sum" },
      { uniqueName: "Quantity", aggregation: "sum" }
    ]
  }
});

const flexmonsterRef = ref<InstanceType<typeof Pivot> | null>(null);

// Example: Customize cell appearance based on data
const customizeCell = (cell: Flexmonster.CellBuilder, data: Flexmonster.CellData) => {
  if (data.isGrandTotalRow && data.measure && data.measure.uniqueName === "Price.sum" && data.value && +data.value > 1000) {
    cell.addClass("high-total-cell");
  }
};

// Example: Access the Flexmonster API after the component is ready
const onReady = () => {
  if (flexmonsterRef.value && flexmonsterRef.value.flexmonster) {
    console.log("Flexmonster instance is ready:", flexmonsterRef.value.flexmonster);
    // You can now interact with the Flexmonster API, e.g., to update data
    // flexmonsterRef.value.flexmonster.updateData({ data: [{ Category: 'Electronics', Price: 300, Quantity: 2 }] });
  }
};
</script>

<template>
  <div class="flexmonster-container">
    <h1>Product Sales Overview</h1>
    <Pivot
      ref="flexmonsterRef"
      :report="report"
      :customizeCellFunction="customizeCell"
      :licenseKey="process.env.VUE_APP_FLEXMONSTER_LICENSE ?? ''" <!-- Use environment variable for license -->
      @ready="onReady"
    />
  </div>
</template>

<style>
.flexmonster-container {
  font-family: Arial, sans-serif;
  padding: 20px;
}
.high-total-cell {
  background-color: #ffe0e0 !important;
  font-weight: bold;
  color: #c00;
}
/* Basic Flexmonster theme adjustments (optional) */
.fm-ui-element {
  font-size: 14px;
}
</style>

view raw JSON →