set different colors for each column in highcharts

后端 未结 4 1516
无人共我
无人共我 2020-11-29 05:53

I need to set different colors for each column in Highcharts graph dynamically. My Highcharts graph is:

options = {
           


        
4条回答
  •  时光取名叫无心
    2020-11-29 06:31

    i had colors from API response and 2 series. second series with dynamic colors.

    following is sample to set dynamic colors while series mapping.

    const response = [{
        'id': 1,
        'name': 'Mango',
        'color': '#83d8b6',
        'stock': 12.0,
        'demand': 28,
      },
      {
        id ': 2,
        'name': 'Banana',
        'color': '#d7e900',
        'stock': 12.0,
        'demand': 28,
      }
    ];
    let chartData: {
      categories: [],
      series: []
    };
    chartData.categories = response.map(x => x.name);
    chartData.series.push({
      name: 'Series 1',
      type: 'column',
      data: response.map(x => x.demand)
    });
    chartData.series.push({
      name: 'Series 2',
      type: 'column',
      data: response.map(x => ({
        y: x.stock,
        color: x.color // set color here dynamically
      }))
    });
    console.log('chartData: ', chartData);

    you could also read more about Highcharts series Point and Marker

提交回复
热议问题