score:2
Accepted answer
i solved the problem by myself. basically i still manually set the series's color each time when a new set of data is inserted. i did this before i post the question and failed because i didn't set the color attribute within the series.
i wrote a function which returns different color according to the index and i call it each time a new set of data is inserted.
var switchcolor = (cnt) => {
var colors = ['#058dc7', '#50b432', '#ed561b', '#dddf00', '#24cbe5', '#64e572', '#ff9655', '#fff263', '#6af9c4'];
return colors[cnt];
}
$(document).ready(function() {
var colorcnt = 1;
var options = {
chart: {
renderto: containerspline,
type: 'spline',
},
title: {
text: '信息录入统计曲线图'
},
credits: {
enabled: false
},
xaxis: {
title: {
text: '时间'
},
categories: []
},
yaxis: {
title: {
text: '数量'
}
},
series: [{
name:'',
data:[]
},
]
};
// show the default data when the web page is firstly loaded
$.get("//localhost:5050", (data)=>{
var series = {
name:'',
data: []
};
var xaxis = {
categories: []
};
data.recordset.foreach((item)=>{
series.data.push(item.count);
series.name = item.dates;
options.xaxis.categories.push(item.times);
})
options.series[0].data = series.data;
options.series[0].name = series.name;
var chart = new highcharts.chart(options);
})
// feed the required data into the chart
$('#query').click(()=>{
var obj = {
year: $('#year').val(),
month: $('#month').val(),
day: $('#day').val()
}
$.post('//localhost:5050',obj, (data)=>{
options.chart.colorcount++;
var series = {
name:'',
data: [],
color: switchcolor(colorcnt++),
};
var xaxis = {
categories: []
};
console.log(data.recordsets);
data.recordset.foreach((item)=>{
series.data.push(item.count);
series.name = item.dates;
options.xaxis.categories.push(item.times);
})
options.series.push(series);
var chart = new highcharts.chart(options);
})
});
// clear the search history
$('#clear').click(() => {
options.series = [{
name: '',
data: []
}]
var chart = new highcharts.chart(options);
colorcnt = 0;
})
})
Source: stackoverflow.com
Related Query
- highcharts change series color when data is dynamically inserted
- change datalabels color in a HighCharts chart when hovering without updating the series
- Highcharts : Change color of series when hovering other series
- How to change line color when loading static csv data into Highcharts Highstock graph?
- How can I change data series dynamically in HighCharts without overwriting initial series?
- How to change color of single column in Highcharts column graph when data is in CSV form?
- Changing data dynamically for a series in Highcharts
- Changing series color in highcharts dynamically
- How do I dynamically change a data point in Highcharts using JavaScript
- Highcharts dynamically change bar color based on value
- Changing Highcharts data series type dynamically
- Change Highcharts Series color
- Change series data dynamically in react-highcharts without re-render of the chart
- Highcharts : Showing wrong color in data series
- Dynamically add data to series in Highcharts
- Highcharts hide series without change legend color
- Highcharts - How do I dynamically change Marker radius when zooming?
- Setting Highcharts Series and Category data dynamically
- How to color series legend in highcharts when colorbypoint is set to true
- HighCharts - Dynamically Change Axis Title Color
- Add data dynamically to the top level in highcharts when drilling up
- Highcharts area range series change plotting area dynamically
- Change color of series onclick events across multiple highcharts
- Highcharts error when add and shift data to hidden series
- Highcharts - change series color on MouseOver
- How to change the color of highcharts series graph to black & white during downloading it as an image?
- Change color code on colum, depending on data value (highchartJS)
- Highcharts: how to change line color when hovering a scatterplot series
- Highcharts Heatmap background color when invalid data
- Highcharts change crosshairs color by number of visible series
More Query from same tag
- Javascript variable with Comma separated values not working in HighChart
- Updating fontsize with highcharts using zoomtype
- Highmaps drillup: Error occurs when setting state in React
- Highcharts showing time instead of date
- Highchart: in bar chart, how to increment a bar according to data?
- Set a custom rangeSelector and disable xAxis label on chart and on Navigator with Highstock
- highstock display tooltip wrong in iframe
- HighCharts API pie chart CSS how to select drilldown labels
- Javascript Code not running in Wordpress Pages
- How to highlight points of multi series in same X value when mouse moves using highcharts?
- Highcharts legend data interactivity issues
- how to customize heatmap highcharts plot area and the color of the datalabels
- Highcharts convert x-axis time to localtime
- How to add a label to axis
- High Charts - HTML in label
- primefaces chart x axis
- HighCharts: Mouse click event is handled by both Series handler and Point handler
- Highcharts chart going blank on compare : 'percent' and type: 'arearange'
- highcharts different tick interval
- Toggle flags on/off with a button in highcharts/highstock
- Format Highcharts chart tooltip pointFormat in formatter
- Populate the chart with values returned by controller
- How to create combo chart with Highcharts
- Disable-Click on Legend in HighCharts Column Graph
- Combine 2 series in one Chart (not stacked)
- Highstock chart - Dates on same x axis and Crazy Tooltip
- Highcharts inactive state must be applied to all items except for hovered item
- Alias "ext.highcharts.HighchartsWidget" is invalid error in yii highchart
- Problems with Highcharts exporting server: Encoding and quality
- Highcharts: Drag Point Over Another Point Invokes Click Event