score:1
To create a chart you have to pass an HTML element that will be a chart container. In your code that what's missing. Check the demo I have prepared to reproduce this issue: https://jsfiddle.net/BlackLabel/c60y1t2v/
Code:
var chartArray = [],
counter = 1,
dataArr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
],
containers = document.getElementById('containers');
function drawChart(data) {
var cnt = document.createElement('div'),
cntId = 'container' + counter++,
chart;
cnt.setAttribute('id', cntId);
containers.appendChild(cnt);
chart = new Highcharts.Chart(cntId, {
title: {
text: "title",
},
xAxis: {
categories: [1, 2, 3, 4],
},
series: [{
type: 'line',
data: data,
}]
});
return chart;
}
dataArr.forEach(function(data) {
var chart = drawChart(data);
chartArray.push(chart);
});
score:0
You need to define options each time you use a new chart. Reinitialize the OriginalOptions every time you create a new chart.
const options = [...Array(5)].map(() => {
const originalOptions = {
series: [{
data: [], // some random data
type: 'column'
}]
}
return Object.assign(originalOptions)
})
Updated:
For dynamically repopulating the chart, you have to initialize an empty chart and then add new series + redraw whenever your data is populated.
Your redraw function will look something like this:
var i = 0;
var data = [];
var chart = new Highcharts.Chart('container',{
series: []
});
var interval = setInterval(function() {
i++;
data[i] = [i*10 + 1, i*10+2, i*10+3];
drawChart(data[i]);
if(i > 2) clearInterval(interval);
},1000);
function drawChart(data) {
var series = {
type: 'line',
data: data
}
chart.addSeries(series, false);
chart.redraw();
}
score:0
Store chart options in Array
then map over to Initialize Highchart for each options.
var chartArray = [];
function drawChart(data1, data2, data3, i) {
// Create container for charts
const el = document.createElement('div');
document.body.appendChild(el).setAttribute("id", "container"+i);
// Create charts
var chart = new Highcharts.chart(el, {
series: [{
type: 'line',
data: data1,
}, {
type: 'line',
data: data2,
}, {
type: 'line',
data: data3,
}]
});
chartArray.push(chart);
console.log(chartArray);
}
var counter = 0;
var delayTime = 2000;
var timer = setInterval(function(){
var data1 = [30, 70, 50];
var data2 = [40, 70, 60];
var data3 = [10, 90, 20];
drawChart(data1, data2, data3, counter);
if(counter == 2){
clearInterval(timer);
}
counter++;
},delayTime);
<script src="https://code.highcharts.com/highcharts.js"></script>
score:0
To Print HTML as PDF you can use this software "wkhtmltopdf"
in Linux you need to use this command :
sudo apt-get install wkhtmltopdf
There are many library based on "wkhtmltopdf" in many languages so you can use it.
Library for PHP : https://github.com/mikehaertl/phpwkhtmltopdf
Source: stackoverflow.com
Related Query
- Storing Highcharts in array issue
- Converted PHP code that built an array to JS and now highcharts doesn't work - what did I do wrong?
- Array issue in rails and highcharts
- Highcharts cloud issue with data source when duplicating chart
- Storing mysqli_query into multidimensional php array and utilizing that array as input to highcharts
- Highcharts - issue about full chart width
- Styling bar colors in Highcharts with a gradient issue
- HighCharts full width issue
- jQuery UI Tabs and Highcharts display/rendering issue
- Highcharts data series issue with ajax/json and PHP
- Highcharts Pie Chart ignores percentageDecimals tooltip setting and has floating point inaccuracy issue
- Highcharts series data array
- Highcharts - HTML tooltip & datalabels render issue
- Use an array of objects for series data in Highcharts
- Library duplication issue using Highcharts in Jaspersoft Studio
- Highcharts multi y-axis min-max issue
- Highcharts - Issue with negative values when displaying multiple axes
- How do I set highcharts line graph point colors to an array of colors?
- highcharts and canvg scaling issue
- Issue Dynamically Changing HighCharts Chart Title
- Highcharts + Bootstrap .table-responsive issue
- How get data name in Highcharts pie chart legend instead of "Slice" using array of values?
- Highcharts yAxis text rotation issue in IE8
- HighCharts Rendering Issue In Chrome
- Highcharts zoom issue after upgrading to jQuery 1.8
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- Highcharts - Global configuration with common code and unique data & Headings
- HighCharts Time-based Quarterly Data - xAxis Label Issue
- How to populate a Highcharts axis with string formatted data from a PHP array
- Highcharts .update modifying original data array
More Query from same tag
- setInterval in Angular JS for HighCharts-ng does not work
- How to use trellis chart with stacked column in Angular 10 using Highcharts
- Angular Highcharts Wordcloud color array
- update table as we click on the stacked highchart based on some logic
- Create Density Heatmap Chart using Jquery with array of data
- How to use scrollbar on highcharts heatmap?
- Change direction of angles in Highcharts
- Highstock navigator style / font
- HighCharts XAxis logarithmic type
- How to create pie chart with only 1 series data and have background be a circle
- How we can format the box size of timeline highchart
- Highcharts column percentage stacked chart worked in v 2.3.5 broken with v 3.0.2
- highcharts additional title opinion
- Highcharts not showing all labels for rows
- Can I let a data value null in highcharts?
- Plot time on Y-axis and users on X-axis Highcharts
- JSON to javascript Date.UTC
- Highcharts returning error 15 but the graph is correct?
- Highcharts manually added svg elements not following stock graph on pan
- Vue3 Multiple Highcharts
- Text Gradient Highcharts Wordcloud
- What is the solution for Highcharts hover
- Highcharts tooltip not working
- How to distinguish Highcharts background color for if statement
- Change Highcharts xAxis step value on chart redraw event?
- How to hide series via the legend in highstock ?
- Drag and drop not working using Highcharts-React
- ERROR TypeError: Cannot read property '0' of undefined in angular-highcharts
- Is it possible to combine mutiple charts with one navigator in highcharts stock?
- Getting coordinates of chart on selecting plot in highcharts