Need to build a heat map? Just define a color scale and change cell coloring based on their values — it is easy to do with the Flexmonster API.
Play with the demo on a larger screen: save this link for later or watch the video review now.
import * as FlexmonsterReact from "react-flexmonster";
import "flexmonster/flexmonster.css";
import tinycolor from "tinycolor2";
function PivotTableDemo() {
const colorScheme = [
"#DF3800",
"#FF6D1E",
"#FF9900",
"#FFB600",
"#A5CE31",
"#6CBD05",
"#00A45A"
];
const minValue = 0;
const maxValue = 15000;
const report = {
dataSource: {
type: "csv",
filename: "https://cdn.flexmonster.com/data/sales.csv"
},
slice: {
rows: [
{
uniqueName: "Month"
},
{
uniqueName: "[Measures]"
}
],
columns: [
{
uniqueName: "Category",
levelName: "Product Name",
filter: {
members: [
"category.[condiments].[bbq sauce]",
"category.[breakfast cereals].[corn flakes]",
"category.[confectionery]",
"category.[bakery].[chocolate biscuits]",
"category.[fruit preserves].[apple jam]",
"category.[bakery].[apple cake]",
"category.[soups].[tomato soup]"
]
}
}
],
measures: [
{
uniqueName: "Revenue",
aggregation: "sum",
format: "currency"
}
]
},
formats: [
{
name: "",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2
},
{
name: "currency",
currencySymbol: "$"
}
]
};
const customizeCellFunction = (cell, data) => {
if (data?.type === "value" && !data?.isGrandTotal) {
const backgroundColor = getColorFromRange(data.value);
const textShadowColor = tinycolor(backgroundColor).darken(15).toString();
const borderColor = tinycolor(backgroundColor).darken(3).toString();
cell.style = {
...cell.style,
"background-color": backgroundColor,
"color": "white",
"font-weight": "bold",
"text-shadow": `0px 2px 3px ${textShadowColor}`,
"border-bottom": `1px solid ${borderColor}`,
"border-right": `1px solid ${borderColor}`
};
}
};
const getColorFromRange = (value) => {
if (isNaN(value)) {
value = minValue;
}
value = Math.max(minValue, Math.min(value, maxValue));
const perc = (minValue + value) / maxValue;
const colorIdx = Math.round((colorScheme.length - 1) * perc);
return colorScheme[colorIdx];
};
return (
<>
<FlexmonsterReact.Pivot
height={600}
report={report}
customizeCell={customizeCellFunction}
/>
</>
);
}
export default PivotTableDemo;
For more details, check our blog post on creating a heat map and use it for your business data. We have got you covered there.
You may also need the Customizing the grid cells guide to explore more options for customizing the React pivot table: alternate row colors, represent numbers by icons, add hyperlinks to cells, and more.
Can't find your answer here?
Visit the FAQ page
Flexmonster Pivot Table & Charts is a JavaScript pivot table component for adding interactive reporting and data analysis to web applications. Users can summarize, filter, sort, and explore data in pivot tables and charts, drill into results, and export reports.
Flexmonster works in plain JavaScript and TypeScript projects. It also integrates with React, Next.js, Angular, Vue, Blazor, and other technologies. See all integration options.
Flexmonster supports JSON and CSV files, SQL databases, MongoDB, Elasticsearch, and Microsoft Analysis Services (SSAS). You can also connect other data sources through your own backend. See supported data sources.
Flexmonster offers licenses for internal corporate use, SaaS products, and OEM distribution. Pricing varies by license and plan. SaaS projects can also use the free SaaS Entry license during development. Learn more on the pricing page.
Yes. Flexmonster offers a 30-day free trial that lets you evaluate all its features. No credit card is required. The trial version has a watermark.
To get started with Flexmonster, follow our integration guide.