-1

i want ro remove that custom color and add that color as loop like first color red then green .odd even odd even.

option = {
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            itemStyle: { color: 'green'},

        },
        {
            name: '邮件营销',
            type: 'line',
            stack: '总量',
            data: [120, 132, 101, 134, 90, 230, 210],
         itemStyle: { color: 'red'},
        }

         ]
    };
Sherin Shaju
  • 246
  • 4
  • 15

1 Answers1

1

Your plan is perfect, what's stopping you do it? What the problem blocks the next steps?

Update: please don't separate question to title and body, I hardly understood what you mean. Title should contain only short summary of question.

Answering your question: the easiest option for control colors is generation series with precomputed color.

Something like this:

  var myChart = echarts.init(document.getElementById('main'));

  var data = [
    [120, 132, 101, 134, 90, 230, 210],
    [340, 280, 310, 360, 280, 310, 410],
    [520, 532, 490, 480, 520, 550, 570],
    [760, 732, 790, 780, 820, 750, 770],
   [820, 932, 901, 934, 1290, 1330, 1320],
  ];

  var series = data.map((sData, idx) => (
    {
      name:  'series' + idx,
      type:  'line',
      data:  sData,
      color: idx % 2 === 0 ? 'red' : 'green',
    }
  ))

  var option = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: series,
  };

  myChart.setOption(option);
<script src="https://cdn.jsdelivr.net/npm/echarts@4.7.0/dist/echarts.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
Sergey Fedorov
  • 3,696
  • 2
  • 17
  • 21