如何在 highcharts boxplot 的系列中隐藏数据?
How to hide data in a series in highcharts boxplot?
我有一个用 highcharts 制作的箱线图,我有 2 个系列,一个用于观察,一个用于异常值。我想在两个系列中隐藏一列,但是 going through the API 似乎没有隐藏数据行的方法,您只能删除一个。有没有一种方法可以使用 API 而不是绕过它?
编辑:关于结构的一些示例:
series: [{
name: 'Observations',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point2",
color: "#00FF00"
}, {
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point1",
color: "#FF00FF"
}]},
{
name: 'Outliers',
type: 'scatter',
data: [
[0, 2],
[1, 5]
]
}
]
这个结构有 2 个系列,第一个系列有箱线图,第二个系列有离群值。在其他图表中,如柱形图,您可以将每一列添加为 series
,这为我提供了更多操作它们的选项,但在这里我将每一列作为一个 data
数组对象。在 Highcharts 中,您可以通过触发系列上的 hide()
函数来隐藏系列,但是您不能隐藏 data
对象,您只能删除它们。我想要做的是在视图中隐藏单个数据数组对象。
作为一种解决方法,我可以从技术上从 data
数组中删除我想要的对象并将其保存在其他地方,直到我需要它,但我想知道是否有更好的方法来做到这一点,可能使用 plotPoints
或任何其他方式。
Here's also a demo from the highcharts website. The data here are an array, but anything in the data API above still work on them. Here's the series api进行比较。
可以借鉴pie
系列原型中pointClass
的setVisible
方法:
var pieSetVisible = Highcharts.seriesTypes.pie.prototype.pointClass.prototype.setVisible,
point1 = chart.series[0].points[0],
point2 = chart.series[1].points[0];
pieSetVisible.call(point1);
pieSetVisible.call(point2);
我找到了解决办法。显然有 2 种替代方法可以使用系列设置箱线图图表(您可以使用图例或 hide()
和 show()
方法隐藏和显示):
series: [{
name: 'Series 1',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point x1",
color: "#00FF00"
}, {
type: 'scatter',
data: [[0, 1], [0,2]] // outlier points
}]},
{
name: 'Series 2',
data: [{
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point x2",
color: "#FF00FF"
}]
// no outliers here
}
]
基本上,您可以将观察值和异常值合二为一 series/column,方法是提供异常值 type: 'scatter'
,如上所示。这种方法的问题在于,出于某种原因,您仍然无法通过调用 hide()
和 show()
方法来隐藏异常值。
另一种方法是将每列观察值和每个离群值观察值放在一个单独的系列中,并赋予两者相同的 x
值(离群值应具有框的 x,在本例中它是 0):
series: [{
name: 'Series 1',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point x1",
color: "#00FF00"
}]},
{
type: 'scatter',
name: 'Series 2: Outliers',
data: [[0, 1], [0,2]]
}
{
name: 'Series 3',
data: [{
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point x2",
color: "#FF00FF"
}]
}
]
要将观察结果和离群值相互叠加,您必须在选项中禁用分组:
plotOptions: {
series: {
grouping: false,
}
},
我有一个用 highcharts 制作的箱线图,我有 2 个系列,一个用于观察,一个用于异常值。我想在两个系列中隐藏一列,但是 going through the API 似乎没有隐藏数据行的方法,您只能删除一个。有没有一种方法可以使用 API 而不是绕过它?
编辑:关于结构的一些示例:
series: [{
name: 'Observations',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point2",
color: "#00FF00"
}, {
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point1",
color: "#FF00FF"
}]},
{
name: 'Outliers',
type: 'scatter',
data: [
[0, 2],
[1, 5]
]
}
]
这个结构有 2 个系列,第一个系列有箱线图,第二个系列有离群值。在其他图表中,如柱形图,您可以将每一列添加为 series
,这为我提供了更多操作它们的选项,但在这里我将每一列作为一个 data
数组对象。在 Highcharts 中,您可以通过触发系列上的 hide()
函数来隐藏系列,但是您不能隐藏 data
对象,您只能删除它们。我想要做的是在视图中隐藏单个数据数组对象。
作为一种解决方法,我可以从技术上从 data
数组中删除我想要的对象并将其保存在其他地方,直到我需要它,但我想知道是否有更好的方法来做到这一点,可能使用 plotPoints
或任何其他方式。
Here's also a demo from the highcharts website. The data here are an array, but anything in the data API above still work on them. Here's the series api进行比较。
可以借鉴pie
系列原型中pointClass
的setVisible
方法:
var pieSetVisible = Highcharts.seriesTypes.pie.prototype.pointClass.prototype.setVisible,
point1 = chart.series[0].points[0],
point2 = chart.series[1].points[0];
pieSetVisible.call(point1);
pieSetVisible.call(point2);
我找到了解决办法。显然有 2 种替代方法可以使用系列设置箱线图图表(您可以使用图例或 hide()
和 show()
方法隐藏和显示):
series: [{
name: 'Series 1',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point x1",
color: "#00FF00"
}, {
type: 'scatter',
data: [[0, 1], [0,2]] // outlier points
}]},
{
name: 'Series 2',
data: [{
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point x2",
color: "#FF00FF"
}]
// no outliers here
}
]
基本上,您可以将观察值和异常值合二为一 series/column,方法是提供异常值 type: 'scatter'
,如上所示。这种方法的问题在于,出于某种原因,您仍然无法通过调用 hide()
和 show()
方法来隐藏异常值。
另一种方法是将每列观察值和每个离群值观察值放在一个单独的系列中,并赋予两者相同的 x
值(离群值应具有框的 x,在本例中它是 0):
series: [{
name: 'Series 1',
data: [{
x: 0,
low: 4,
q1: 9,
median: 9,
q3: 1,
high: 10,
name: "Point x1",
color: "#00FF00"
}]},
{
type: 'scatter',
name: 'Series 2: Outliers',
data: [[0, 1], [0,2]]
}
{
name: 'Series 3',
data: [{
x: 1,
low: 5,
q1: 7,
median: 3,
q3: 6,
high: 2,
name: "Point x2",
color: "#FF00FF"
}]
}
]
要将观察结果和离群值相互叠加,您必须在选项中禁用分组:
plotOptions: {
series: {
grouping: false,
}
},