Loading CSV Data from WP Media into Chart
-
Hello everabody,
I am trying to implement charts into a new webpage using amcharts. Implementing the charts works but I have troubles using the dataloader to use data from a csv file I have uploaded to wp Media.
Resources:
//www.amcharts.com/lib/5/index.js //www.amcharts.com/lib/5/xy.js //www.amcharts.com/lib/5/themes/Animated.js
HTML:
<div id="$CHART$" style="width: 100%; height: 300px;"></div>
Java Script:
// Create root element // https://www.amcharts.com/docs/v5/getting-started/#Root_element var root = am5.Root.new("$CHART$"); // Set themes // https://www.amcharts.com/docs/v5/concepts/themes/ root.setThemes([ am5themes_Animated.new(root) ]); // Create chart // https://www.amcharts.com/docs/v5/charts/xy-chart/ var chart = root.container.children.push(am5xy.XYChart.new(root, { panX: true, panY: true, wheelX: "panX", wheelY: "zoomX", pinchZoomX:true dataSets: [{ dataLoader: { url: "https://*******.******/wp-content/uploads/2022/12/SingleDual_v2_4m_2.83.csv", format: "csv", delimiter: ",", // column separator useColumnNames: true, // use first row for column names skip: 1 // skip header row } }] })); // Create axes // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/ var xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, { logarithmic: true, renderer: am5xy.AxisRendererX.new(root, {}) })); var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, { renderer: am5xy.AxisRendererY.new(root, {}) })); // Add series // https://www.amcharts.com/docs/v5/charts/xy-chart/series/ var series = chart.series.push(am5xy.LineSeries.new(root, { xAxis: xAxis, yAxis: yAxis, valueYField: "single", valueXField: "freq", tooltip: am5.Tooltip.new(root, { labelText: "{valueX}: {valueY}" }) })); series.strokes.template.setAll({ strokeWidth: 3 }); series.data.setAll(data); // Make stuff animate on load // https://www.amcharts.com/docs/v5/concepts/animations/ series.appear(1000); chart.appear(1000, 100);
I understand that the code would not work like this but I have not found the correct way to implement the dataloader in wordpress in an example. Only in the github example is in github I understand. And the shortcode example to load a csv via shortcode does not help me to understand how to than use the csv data in Javascript as data for the chart?
Kind regards,
Finn
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Loading CSV Data from WP Media into Chart’ is closed to new replies.