score:1
The scatter plot linked in the comments by @TKoL shows two main differences from your code:
- You need to define the
chart.type
to bescatter
- The data should be in the format of
[[y, x]]
for the scatter plot to be able to match y to x locations.
Defining the type is fixed by adding a property to your config:
Hichcarts.chart("container", {
chart: { type: "scatter" },
/* ... */
})
To zip your x and y values, you can loop over two arrays and merge based on index.
A quick one liner (might not be best performing or readable production code version):
const zip = (ys, xs) =>
xs.reduce(
(acc, x, i) => (acc.push([x, ys[i]]), acc),
[]
);
Note: You might want to ensure your xs
and ys
are of equal length and determine the strategy when they're not (throw an error, get rid of values that are not in a pair, etc.)
Here's a minimal example that uses your data in a scatter plot:
const xValues = [33, 141, 240, 340, 441, 514, 645, 743, 852, 961, 1064, 1172, 1279, 1385, 1495, 1607];
const yValues = [2, 4, 1, 7, 5, 2, 9, 4, 6, 9, 3, 6, 2, 9, 3, 6];
const zip = (ys, xs) => xs.reduce((acc, x, i) => (acc.push([x, ys[i]]), acc), []);
Highcharts.chart('container', {
chart: {
type: 'scatter'
},
series: [{
name: 'Installation',
data: zip(xValues, yValues)
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 800px; margin: 0 auto"></div>
score:0
https://jsfiddle.net/1s5ctbn2/
You need your series data to look like this:
series: [{
name: 'Installation',
data: [
{y:2,x:1.5},
{y:4,x:2.2},
{y:1,x:3},
{y:7,x:4},
{y:5,x:5},
{y:2,x:6},
{y:9,x:7},
{y:4,x:8},
{y:6,x:9},
{y:9,x:10},
{y:3,x:11},
{y:6,x:12},
{y:2,x:13},
{y:9,x:14},
{y:3,x:15},
{y:6,x:20}
]
}]
With both x and y values
Source: stackoverflow.com
Related Query
- Plot Y axis data based on x axis values from a csv file : Highcharts
- How to make the Y Axis values not start from 0 in highcharts? How to display forcefully display the last category data on X axis in HighCharts ?
- Highcharts not displaying data but drawing chart when reading from CSV file
- Highcharts Highstock How to Plot OHLC and Line Charts from One Set of Embedded CSV Data Using Series Map Tools?
- Highcharts to display area range and line chart with data from a CSV file
- Export data from highcharts in csv file with dates in milliseconds
- Highcharts chart not displaying data from csv file
- How can i change highcharts data values by selecting from a dropdown list
- Exporting highcharts data to CSV file
- How to populate a Highcharts axis with string formatted data from a PHP array
- HighCharts scatter plot with Datetime on X Axis not plotting values correctly
- Highcharts Custom display of tooltips, based on data series values
- load data in highcharts from 2 different csv files
- Fetch data from firebase firestore and plot histogram using highcharts when cardview clicked - android
- passing json values to highcharts from .net code behind
- Highcharts fill map based on data values with React TypeScript
- Highcharts stock chart based on data from Quandl API
- Plot Highcharts data from past 30 days with Ruby on Rails
- Highcharts dynamicly update chart from csv file
- Highcharts series visibility with csv data source
- Trouble getting unique tooltip based on X axis values in highcharts line graph
- Scrape Highcharts data to CSV file
- Highcharts with values from multiple JSON file
- How to shift data using Series.addPoint without shifting x axis values in highcharts
- Reverse Axis in Highcharts get data from table
- How to show an additional column from CSV file as a tooltip in Highcharts
- Highcharts plot band to last datetime value from spreadsheet data
- Dynamically adjust Y axis min/max based on ajax update and data points in Highcharts
- Override auto generated Y axis plot area values in Highcharts
- Display data from CSV in Highcharts with Angular
More Query from same tag
- Highchart display single entry against each category in bar chart
- R Highcharter: Changing xAxis Type from datetime to category
- How automatic xAxis labels rotation in highchart
- Highcharts stacked bar with datetime, not able to set start date
- How to set two series for one category in highchart?
- How to make Highcharts default pie not show when Angular page loading
- Goal line in donut chart
- Impossible to have plotband through current date in Highcharts
- Editing Highcharts.js donut data programmatically va JS
- set chart type property in devexpress chart control c#
- Highchart reduce gap size in heatmap and data missing
- How to set the url of moment.min.js to local js file when highcharts exporting png file
- Increase Height Of Chart On Export
- Changing yAxis and plotOptions for drilldown
- How can I create a chart with stacked columns after drilldown?
- Highstock, split tooltip and opposite xAxis?
- Highcharts rendering is taking lot of time in IE11
- multiple Drilldown in Highcharts using values from database in ruby on rails
- How to extend Tooltip Range in Highcharts
- Highcharts bug with labels
- I'm trying to use highcharts to display a series of points not just x and y
- How can I do a dual axis using highcharter library?
- PHP mySQL Highcharts Json Multiselect
- include two series from database in a highchart chart
- How to draw a bubble map with longitude and latitude using Highcharts in react
- highcharts and different yAxis for different categories
- show value if multiple y values on xAxis are used
- How to draw a Horizontal line using Highcharts DotNet C#
- Charts not responding on the web page after printing them
- Create custom Map for Highmaps using Shapefiles and QGIS