score:3
The chart object contains minIndex
and maxIndex
properties that can be used to slice
the dataset for the visible values.
Here's a snippet showing how to use the plugin-provided functions onPanComplete
and onZoomComplete
to output the visible values after panning or zooming the chart:
function getVisibleValues({
chart
}) {
let x = chart.scales["x-axis-0"];
document.getElementById("vv").innerText = JSON.stringify(chart.data.datasets[0].data.slice(x.minIndex, x.maxIndex + 1));
}
new Chart(document.getElementById("chart"), {
type: "line",
data: {
labels: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
datasets: [{
data: [0, 1, 2, 4, 8, 16, 32, 64, 128, 256]
}]
},
options: {
maintainAspectRatio: false,
scales: {
xAxes: [{
ticks: {
min: 'c',
max: 'h'
}
}]
},
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'x',
onPanComplete: getVisibleValues
},
zoom: {
enabled: true,
mode: 'x',
onZoomComplete: getVisibleValues
}
}
}
}
});
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.1"></script>
<script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@0.7.4"></script>
<canvas id="chart" style="max-height:125px"></canvas>
<p>
Visible values: <span id="vv"></span>
</p>
score:0
The toBase64Image
function does not what you want, it just gets the data URL from the canvas.
toBase64Image on github.com/chartjs
toBase64Image: function() {
return this.canvas.toDataURL.apply(this.canvas, arguments);
},
You can get the updated chart data with onZoomComplete
and onPanComplete
, they both get an object that contains chart
from this you might get more information about the current zoom, but as far as I can see you will need to do some calculations/work to get the visible points...
Source: stackoverflow.com
Related Query
- Chart.js get array of currently visible points on graph
- How to access or get value of specific graph on chart plot by click event?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- chartjs-plugin-zoom: get currently visible values when the page first loads
- Chart Js - Limit points on graph without limiting data
- Is there any way to show a tooltip for points which are not visible on the chart in Chart.js?
- Sum of visible Points in ChartJs Bar Chart
- How can i get the Chart JS Bar Graph Bar Label and Value on click?
- Get Chart js object from selector
- Chart.js drag points on linear chart
- How to add datas to chart js from javascript array itself?
- ChartJS: get points information on hovering the points
- Chart JS show multiple data points for the same label
- get yLabel value onclick chart js
- Can't get bar chart colors in Chart js working in React Js
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- Chart js - Get bar width after render
- Get X, Y onClick chart coordinates in ChartJS
- ChartJs line chart - display permanent icon above some data points with text on hover
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- React ChartJS 2 : Get data on clicking the chart
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- Chart.js - data points get smaller after hover
- How to get the actual chart width and height in chart.js
- ChartJS - handling of overlapping points in line chart
- Chartjs (Non Vue) Not Rendering Graph Chart inside V-if/V-show
- Wrong chart.js points get highlighted on hover
- High and low points on chart getting cut off
- Redraw Chart.js Chart with Json_encoded array from ajax request
- Is it possible to make points in a line chart of Chart JS 3.7.0 look like a donut?
More Query from same tag
- Replacing data chart.js and reloading chart [PHP/Js/AJAX]
- How to create a graph where the vertical axis (Y-axis) is a string?
- How to draw multiple color bar in a bar chart using chart.js
- Plot bar graph in reactjs
- Stacked Bar chart fixed width bar chart issue - Chartjs
- live update ecg chart with python and flask
- ChartJS keeps adding one day to X axis. I cannot find a reason. Any suggestion?
- Using Chart.js with Pyramid Web Framework
- ChartJS Bar Issue - Showing "zeros" and not center bars
- Charts.js in Django: Charts cannot appear
- ChartJS adding shadow color to grid and custom x-axis labels
- Default font size doesn't change ChartJS
- Error: $injector:modulerr Module Error - chart.js
- How to add arrays to the barChart with chart.js?
- Pause horizontal scrolling in chart.js for real time data
- Implementing ChartJs
- Can JS lib can be use in Native Tizen App?
- chart.js: Show labels outside pie chart
- Merge two objects with different keys in chartjs bar
- Having trouble fetching data from database for chart in ASP .NET Core
- chart.js add second line in a Line chart that starts from end of first line
- Passing Array to Chart.js not working, chart not rendering
- tooltip messes up bar chart in Chart.js
- Chart.js - Getting data from HTML
- Charts.js Multi Line scales. See value curve
- chart.js how to make x-axis labels position top
- Change <p> and <h> element when selecting something from dropdown
- ChartJS - Show percentage base on data on hover (AngularJS)
- How to remove Grid lines except for zero line and border Chartjs?
- chart.js bar chart datalabel vanishes on hovering over chart