【发布时间】:2021-03-05 12:49:51
【问题描述】:
我正在尝试捕获此问题Chart.js get array of currently visible points on graph 中所示的数据,并且我正在努力实现这一目标。但是,在检查我的 x 轴 0 的属性时,我没有找到线程中详述的 minIndex 或 maxIndex。我确实有 max 和 min 属性,但就我的尝试而言,这些似乎不适用于切片。好奇chartjs方面的高手能否帮我搞清楚minIndex和maxIndex变量。
编辑更多细节: 所以我认为问题可能是在提供的链接中,该示例使用分类数据,而在我自己的示例中,我将 xaxis 作为时间数据?我尝试了 jsfiddle,我在类别类型上看到了 minIndex 和 maxIndex,而在我的时间类型轴上没有看到它们。
我在 x 轴 0 的控制台日志中看到以下内容
n {id: "x-axis-0", type: "time", options: {…}, ctx:
CanvasRenderingContext2D, chart: en, …}
bottom: 475
chart: en {id: 0, ctx: CanvasRenderingContext2D, canvas: canvas#myChart.chartjs-render-monitor, config: {…}, width: 1110, …}
ctx: CanvasRenderingContext2D {canvas: canvas#myChart.chartjs-render-monitor, globalAlpha: 1, globalCompositeOperation: "source-over", filter: "none", imageSmoothingEnabled: true, …}
fullWidth: false
height: 15.76
hidden: false
id: "x-axis-0"
labelRotation: 0
left: 35.781484375
longestLabelWidth: 0
longestTextCache: {normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif: {…}}
margins: {left: 35.781484375, right: 3, top: 0, bottom: 0}
max: 1614922685400.2363
maxHeight: 237.5
maxWidth: 1074.218515625
min: 1614922568591.0784
minSize: {width: 1074.218515625, height: 15.76}
options: {display: true, position: "bottom", offset: false, gridLines: {…}, scaleLabel: {…}, …}
paddingBottom: 0
paddingLeft: 3
paddingRight: 3
paddingTop: 0
position: "bottom"
right: 1107
ticks: []
top: 459.24
type: "time"
weight: 0
width: 1071.218515625
_adapter: rn {options: {…}}
_endPixel: 1107
_gridLineItems: [ticksLength: 0, borderValue: 459.5]
_labelItems: []
_labelSizes: {first: {…}, last: {…}, widest: {…}, highest: {…}}
_layers: ƒ ()
_length: 1071.218515625
_majorUnit: undefined
_maxLabelLines: 0
_offsets: {start: 0, end: 0, factor: 1}
_reversePixels: false
_startPixel: 35.781484375
_table: (2) [{…}, {…}]
_ticks: []
_ticksToDraw: []
_timestamps: {data: Array(3601), datasets: Array(2), labels: Array(3616)}
_unit: "hour"
__proto__: n
编辑 2: 我为此 https://jsfiddle.net/d489uesh/ 创建了一个 jfiddle 只是为了进行实验,我为 minIndex 的值做了一个控制台日志,它似乎只有 0 或 1,如果我使用时间作为轴的类型,它根本不起作用。所有这一切的最终目标是使用检索到的 y 值数组来计算拖动突出显示缩放选择的平均值,我觉得我已经很接近了,所以感谢任何帮助!
【问题讨论】:
标签: chart.js