score:30
Accepted answer
Dev 2.0 of chart js supports an option to reverse the ticks when setting up the axis so your declaration of the second axis would become
{
type: "invertedLinear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: "right",
id: "y-axis-2",
ticks: {
reverse: true
},
// grid line settings
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
}
}
Here it is in action https://jsfiddle.net/nwc8ys34/15/
score:1
In v3 the scale configs have been changed so the desired behaviour can be accomplished like so:
const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [40, 80, 100, 70, 60, 80],
borderColor: 'pink'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'orange',
yAxisID: 'y2'
}
]
},
options: {
scales: {
y: {},
y2: {
position: 'right',
reverse: true
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
const chart = new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
</body>
score:23
Using v 2.7.0, and the following seems to work:
options: {
scales: {
yAxes: [{
ticks: {
reverse: true,
}
}]
}
}
Source: stackoverflow.com
Related Query
- How do you set x and y axis and Title for a line chart using charts.js?
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- How to constantly update y axis using a C# function to update a Live (Streaming) Chart.js Chart in ASP.NET core Web Application Razor Pages
- How can I automatically rescale the y axis of my log chart using ChartJS?
- How to run Chart.js samples using source code
- How to add text inside the doughnut chart using Chart.js?
- How do I invert an y-axis using chart.js (v2.0-dev)
- How to add an on click event to my Line chart using Chart.js
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to Draw Gantt chart using chart js or other libraries
- How to add text in centre of the doughnut chart using Chart.js?
- How to create stacked bar chart using react-chartjs-2?
- How do I change the 'months' language displayed on the date axis in Chart JS?
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to display the labels in doughnut chart using ng2 charts?
- How to create single value Doughnut or Pie chart using Chart.js?
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- How to make a chart scroll horizontally (when using Chart.js)
- How to hide axis using Chartkick.js
- How to create a gantt chart using Chart.js and populate dates?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- Using chart js version 3, how to add custom data to external tooltip?
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- chart data on 24hr X axis using recharts, chart.js, I don't mind what
- Change Axis Line color in Chart created using chart.js
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- How to Remove axis Lines from chart in chart js
More Query from same tag
- Displaying ChartJS tooltip on mouseover of bar/line
- how to make scrollable the legends of pie chart ( chart js )
- React js Unhandled Rejection (TypeError): t[l].data.map is not a function
- Show gridlines over graph in chart.js, show bold x-axis label in chart.js, mixure of intersecting graph colors in chart.js
- interactive Button doesn't hide the chart as I intended
- Remove Chart.js Gridline Overlap
- Chart JS not re rendering in Laravel Livewire
- How to set a time scale to a ChartJS chart from JSON?
- Scatter plot not showing anything chartjs needs some debugging
- Chart.js showing old chart on hover
- ChartJS different border color for legend
- Chart JS - Grid colors and gradient fill not showing
- Using a prepared dataset in chart.js
- Chart.js - Hide tooltip caret
- Chart.js 2.0 doughnut tooltip percentages
- How to use icon as legend in Chart.js?
- How to get x-axis value in chart as string?
- Chart.JS add dataset from hidden input
- Overlap horizontalBar graps using ChartJS
- AddData in Chart.js 2.0
- Combine multiple columns values to one label in chart.js
- Moving vertical line when hovering over the chart using chart.js
- chartjs resizing very quickly (flickering) on mouseover
- How I can prevent of labels overlapping on mobile screen Chart.js
- How to generate colors for unknown number of datasets in Chartjs
- Add a second Y-axis for Linechart in Chart.js?
- chartjs-plugin-dragdata isn''t working with scatter charts
- JSON Data Assigning to Javascript Var Value
- How to display value after the bar using chart.js
- how to change object properties by on-click