Quadrant Chart
Overview
Technically, a quadrant chart is a scatter chart divided into four quarters (quadrants) to make the visualization more readable. This chart type is used when data can be categorized into quadrants - for example, in SWOT-analysis.
In AnyChart, Quadrant charts are combined with Marker, Bubble, and Line series.
This article explains how to create a basic Quadrant chart as well as configure settings that are specific to the type.
Modules
The Quadrant chart requires adding the the Core and Scatter modules:
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-scatter.min.js"></script>
Alternatively, you can use the Base module, which includes, among other things, the two modules mentioned above:
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-base.min.js"></script>
Learn more: Modules.
Quick Start
To create a Quadrant chart, use the anychart.quadrant() chart constructor.
This constructor creates a Scatter chart with some predefined settings:
- The chart is framed with two X- and Y-axes.
- Ticks and labels on the axes are disabled.
- There are no grids.
- The minimum and maximum values of the scales are 0 and 100.
- The right-top and left-bottom quarters are colored.
Like the scatter constructor, it processes data points as-is: sets of arguments from different series don't influence each other, points are shown in the exact order they are set, and lines can be vertical and cross themselves. While the Cartesian constructor distributes points along the X-axis at equal intervals (categories), the scatter and quadrant constructors distribute points according to their values.
If you just pass the data to the chart constructor, it creates a Marker series. But you can also create a Marker, Bubble, or Line series explicitly by using one these methods:
The following sample demonstrates how a basic Quadrant chart is created:
// create data
var data = [
{x: 4, value: 42},
{x: 13, value: 59},
{x: 25, value: 68},
{x: 25, value: 63},
{x: 44, value: 54},
{x: 55, value: 58},
{x: 56, value: 46},
{x: 60, value: 54},
{x: 72, value: 73}
];
// create a chart
chart = anychart.quadrant(data);
// set the container id
chart.container("container");
// initiate drawing the chart
chart.draw();
General Settings
In AnyChart there are many settings that are configured in the same way for all chart types, including the Quadrant chart (for example, legend and interactivity settings).
Read the overview of general settings: General Settings.
Special Settings
Appearance
Each of the supported series types has its own visual settings - see the following articles:
Also, you can learn more from the Appearance Settings and States sections.
In this sample there are three series (Marker, Line, and Bubble) with appearance settings configured:
// create the first series (marker)
var series1 = chart.marker(data_1);
// configure the visual settings of the first series
series1.normal().fill("black", 0.3);
series1.hovered().fill("black", 0.1);
series1.selected().fill("black", 0.5);
series1.normal().stroke("black", 1);
series1.hovered().stroke("black", 2);
series1.selected().stroke("black", 4);
// create the second series (line)
var series2 = chart.line(data_2);
// configure the visual settings of the second series
series2.normal().stroke("#00cc99", 3, "10 5", "round");
// create the third series (bubble)
var series3 = chart.bubble(data_3);
// configure the visual settings of the third series
series3.normal().fill("#0066cc", 0.3);
series3.hovered().fill("#0066cc", 0.1);
series3.selected().fill("#0066cc", 0.5);
series3.normal().stroke("#0066cc");
series3.hovered().stroke("#0066cc", 2);
series3.selected().stroke("#0066cc", 4);
Quarters
Each Quadrant chart has four quarters (quadrants), which can be configured separately. Use these methods to access and configure them:
To set the fill and stroke of quarters, combine these methods mentioned above with:
To set the fype and radius of corners, call:
You can also configure titles, margins, paddings, and labels of quarters (see Labels to learn more):
The sample below shows how to set the fill and corners:
// configure quarters
chart.quarters(
{
rightTop: {
fill: "#ccfff2",
corners: 30,
cornerType: "cut"
},
rightBottom: {
fill: "#e6f9ff",
corners: 30,
cornerType: "cut"
}
);
The following sample shows how to set titles:
// configure quarters
chart.quarters(
{
rightTop: {
title: {
text: "Right Top",
fontColor: "#fa8072",
fontSize: "24",
fontWeight: "bold"
}
},
rightBottom: {
title: {
fontColor: "#72fa80",
text: "Right Bottom",
fontSize: "24",
fontWeight: "bold"
}
},
}
);
Crossing
To configure the intersecting lines ("crossing") in the center of a Quadrant chart, use the stroke() method:
// configure the crossing
chart.crossing().stroke("gray", 3, "7 3", "round");
Scales
In Quadrant charts data do not affect scales: the data falling outside scales just are not displayed.
By default, the minimum and maximum values of the X- and Y-scales are 0 and 100, but you can change these settings (read more in the Scales article):
// configure scales
chart.yScale().minimum(-100);
chart.yScale().maximum(100);
chart.xScale().minimum(-100);
chart.xScale().maximum(100);
Please note that quarters always divide scales into two parts, no matter what the minimum and maximum values are. So, the lines in the center of the chart ("crossing") intersect in the origin only in one case: if the minimum and maximum values are of the same absolute value, like in the sample code above. You can go to the Axes section to see how it looks like.
Axes
The Quadrant chart is framed by two X- and Y-axes, which can be referred to by indexes (0 and 1). By default, ticks, labels, and titles are disabled, but you can enable them - read more in the Axes and Grids article:
// configure axes
chart.xAxis(0, {ticks: true, labels: true});
chart.xAxis(1, {ticks: true, labels: true});
chart.yAxis(0, {ticks: true, labels: true});
chart.yAxis(1, {ticks: true, labels: true});
Labels
Labels are text or image elements that can be placed anywhere on any chart (you can enable them on a whole series or in a single point). For text labels, font settings and text formatters are available.
Labels of series are configured according to the rules of the series type - for example, see the Marker Chart article. You can also configure labels of quarters by using the label() method. Please note that a quarter can have more than one label.
The sample below shows how to create quarter labels:
// create the first label on the left-bottom quarter
var labelLBottom1 = chart.quarters().leftBottom().label(0);
labelLBottom1.text("3");
labelLBottom1.fontColor("gray");
labelLBottom1.fontSize(16);
labelLBottom1.fontWeight("bold");
labelLBottom1.position("rightTop");
labelLBottom1.offsetX(-20);
labelLBottom1.offsetY(20);
// create the second label on the left-bottom quarter
var labelLBottom2 = chart.quarters().leftBottom().label(1);
labelLBottom2.useHtml(true);
labelLBottom2.text("Important / Not Important →");
labelLBottom2.position("leftBottom");
labelLBottom2.offsetX(-20);
labelLBottom2.offsetY(-100);
labelLBottom2.rotation(-90);
Tooltips
A Tooltip is a text box displayed when a point on a chart is hovered over. There is a number of visual and other settings available: for example, you can edit the text by using font settings and text formatters, change the style of background, adjust the position of a tooltip, and so on.
Labels of series are configured according to the rules of the series type - for example, see the Marker Chart article.