score:2
Accepted answer
I can propose a simple solution that works but didn't find the reason why your code is not working.
The data
property of individual datasets for a line chart can be passed in two formats, number[]
or Point[]
. Point[]
is useful in the following cases:
- If the number of data points from individual datasets is different.
- if x-values of data points from different datasets are different.
If you have a unique dataset, it's fine to use number[]
and this is what you did.
I just tried the other approach and use Point[]
now. I basically create an array of Point
using Array.map()
:
labels.map((label, index) => ({ x: label, y: dBs[index] }))
Please have a look at your amended code below.
var labels = [100000,100069,100334,100342,100417,129547,129637,129980,129999,130010,130057,130154,130166,130442,130461,159596,159634,159693,159749,159812,160001,160083,160329,160361,160372,160444,160500,199998,200013,200030,200056,200067,200078,200098,200122,200163,200367,200417,200440,249557,249768,249890,249923,249943,250001,250015,250034,250099,250228,250355,250387,319602,319632,319707,319885,319948,319972,320000,320005,320019,320277,320399,320479,399637,399685,399727,399731,399744,399844,399887,399901,400000,400004,400085,400159,499615,499671,499675,499890,499995,499998,499999,500077,500080,500103,500128,500306,629817,629985,629987,629991,629993,629996,629999,630000,630002,630177,630317,789576,789587,789994,789997,789998,789999,790000,790009,790056,790151,790251,999745,999996,999997,999998,999999,1000000,1300000,1600000,2000000,2500000,3200000,4000000,5000000,6300000,7900000,10000000,13000000,16000000,20000000,25000000,30000000,40000000,50000000,70000000,79400000,100000000,126000000,158000000,180000000,200000000,316000000,398000000,501000000,631000000,794000000,1000000000,2000000000,2400000000,3600000000,4900000000,5000000000,5900000000,6500000000,7000000000,8000000000,10000000000,15000000000,18000000000,20000000000,25000000000,30000000000,35000000000,40000000000];
var dBs = [52.886,52.896,52.935,52.936,52.947,57.19,57.203,57.253,57.256,57.258,57.265,57.261,57.261,57.25,57.249,56.091,56.09,56.087,56.085,56.083,56.075,56.07,56.055,56.053,56.054,56.062,56.068,60.254,60.256,60.257,60.26,60.262,60.263,60.265,60.268,60.272,60.274,60.274,60.274,60.71,60.712,60.713,60.713,60.715,60.719,60.72,60.721,60.725,60.733,60.741,60.743,65.011,65.013,65.018,65.029,65.033,65.034,65.035,65.035,65.035,65.04,65.043,65.044,66.61,66.611,66.612,66.612,66.612,66.614,66.615,66.615,66.618,66.618,66.62,66.621,68.6,68.601,68.602,68.606,68.608,68.608,68.608,68.609,68.609,68.609,68.609,68.611,67.968,67.967,67.967,67.967,67.967,67.967,67.967,67.967,67.967,67.971,67.974,71.441,71.441,71.449,71.449,71.449,71.449,71.449,71.449,71.45,71.452,71.453,75.083,75.084,75.084,75.084,75.084,75.084,75.183,70.581,76.635,75.944,73.984,66.849,73.645,80.024,75.646,78.859,85.134,85.876,80.615,80.01,85,79,78,75,62.188,62.728,65.358,75.284,69.098,76.87,80.797,81.103,77.744,77.868,78.514,78.927,75.915,74.093,87.656,85.332,85.204,81.294,82.458,82.045,83.241,77.861,83.363,71.05,61.6,62.5,75.7,67.7,66.7];
var ctx = document.getElementById("myChart2").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'My Dataset',
data: labels.map((label, index) => ({ x: label, y: dBs[index] }))
}]
},
options: {
maintainAspectRatio: false,
scales: {
xAxes: [{
type: 'logarithmic',
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart2" height="200"></canvas>
Source: stackoverflow.com
Related Query
- Why is my chart.js not plotting correctly when changed to logarithmic?
- Stacked line chart not displaying correctly when Xaxis is time
- 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
- why i have this error Utils is not defined when i want create a chart from chart.js
- Why can I not see a data value when hovering over a point on the radar chart?
- Uncaught TypeError: Chart is not a constructor when using Chart.js
- vue.js vue-chartjs chart not updating when chartData replaced, updated etc
- Why chart.js charts are not plotting data in Safari (works in Chrome)
- Chart.js chart does not display when inside an ngIf.
- Css style not working well when resizing chart height in angular application
- Vertical Bar Chart not displaying Correctly
- Chart JS chart not rendering in ArcGIS popup when using navigation arrows
- charts js, doughnut chart not rendering tooptips correctly
- Bar Chart Not Stacking When Using ChartJs
- Why is this bar chart using chart.js not rendering in react.js?
- vue-chart.js / vuex: Chart not updating when vuex state changes
- Chartjs Stacked bar chart not displaying correctly
- chart.js one of the chart from mixed chart is not plotting
- Chartjs does not render chart when set responsive option to true
- Problem with script src for Chart.js. The CDN for Chart.js funtions fine, so my code is ok. Somehow I'm not linking the file correctly
- colors are not updated when updating chart
- Line Chart is not setting backgroundColor when created dynamically Chart.js
- vue-chartjs not working properly in flexbox and when resize chart goes blank
- Angular-Charts bar chart does not update when I change the data, series, labels
- Why is Chart js first bar too small or not showing at all?
- Destroying chart.js is not working when chart created inside function - chart.destroy() is not a function
- Bar Chart not displaying when using chart.js
- Why ChartJS's Bar Chart does not render bar for a specific value?
- Why does chart update fail when its container has ng-show on it?
- ChartJS Bar Chart not respecting disabled legend when using cdn
More Query from same tag
- Data not fully displaying on bar chart
- how to change the label color and set y-axis values 1k intervals and hide y-axis?
- not able to move my range slector
- Center point labels between ticks (Polar Area Chart JS)
- Chart.js Show label/tooltip for single point when multiple points coincide
- Chartjs: Is it possible to hide the data labels on the axis but show up on the graph on hover?
- Issues with Moment and ChartJS Time Format Parsing
- How to create vertical arbitrary line in financial chart?
- Disable chartJS tool tip on one dataset only
- Chart.js. Values in a big range. The smallest values are not available
- How to separete chart series into different pane (Chart.js)
- Chart.js axes always show zero
- ChartJS add text to canvas in linechart
- How to Reset a Chart of Chart.Js?
- Loading json file to chartjs
- Chart.js styling questions
- Error: Failed to create chart: can't acquire context from the given item
- Chart js always show labels on a doughnut chart
- How to display data by current month and display no data message if data not exists
- Show value on Mixed chart, Charts.js
- Django and ChartJS
- How to access the Chart object in Javascript DOM?
- Remove blank space in chart.js chart
- Chart.js group data by month\year
- Charting Commodity Data - Issue getting the dates and values in JSON
- Trying to access key in JSON array
- How to noshown the scale while all datasets is hidden (chartjs)?
- How to add OnClick Event on labels in Chart.js v2.0?
- Chart.js combine two pieces of data into one bar
- Vue-Chartjs not rendering graph