echarts [Bug] Init echart with theme and no theme the color in chart is different

cngwdvgl  于 4个月前  发布在  Echarts
关注(0)|答案(3)|浏览(38)

Version

5.4.3

https://echarts.apache.org/examples/zh/editor.html?c=line-simple&version=5.4.3&theme=dark&code=PYBwLglsB2AEC8sDeAoW7YCIAeBBbEAzpgFzJoaWZgCeIApqVgMYCGY9A5sAE42YAaCpXSZorALb0AMsDaQYTTPWgATQcJGYARsACua1nwDirEEwBmrADaF6QkRkysChaa231rTVI8eYJI04IaCYARgAGBz8qZmBrXiUeTm1WAAoAJjCwgVgsnLzs3IiAOgBWAEoNGKoLGDAAMUkIa34yTABZCGYeYEJgCzBYAE1WAAl6CGqa0TroMABlCAAvRjIwjOiZzEIAC2AAdyYwHj16TUoAXy2tFyJpELXyGdFrR4XaayffF9j4xPaAGIygA2UGg6a_UR7Q6WGx2C5-a6I_wwo5kE5nFGwZExZyuAAq3QA1j5sVQ0XDbPZyU43tB6B8aF8yVCnHEEjwlMCwbzMLT0Jdsbi_DsQG8wLgePRWKyXs5pawmSyyD82ZgOQDYABtAU1TDJVJpMIAZjKAgyERBFrKUVKYSqNzZokN6VN5st1oytoEESqesoAF0nfLKRjTudfiLtmHYFZqcKQ9DxRAwA8GXLtvTGZ9vgH2f8uUDwXyk_raAwlKpWHt6Oo9dH9bH4wiYo2qNWwLKyLrfphLWEypD9QOQcO8QOAOzj0UDgAcM_8A4AnPyYsHsTt9ujYJiaXjxFJTOZ1mVNI3MDR8ERM1pY3uy9Q6E9MAA3GxnRdYO5uDxeW94pqRZYK6mRFIUBT5MU5SOnqmBzI0zStEoXQ9H0AxDKMExTGWtT1EsqzhJscH3hGuFOO-1hnA0vCBGASjQDAjDkS6wBdhwTARImm4_umeZ9tmyr8c6GqFtyJYQg2LFYM28KRkij4_kSzCkqqJHblSdjSZggm5gB8pAeJvKSVG3F4oQKaSoq-n-EYMpCTZTYaWQLb7iJhk9vm_ige6FpWjadolA6X59j5Zp-V6Pp-muzqBlJ6mwi5clmaKFkSnx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iqA915LRHuU08cEJkLIuAdi6Z5LybMvP0_UnWCzbfZCDhsjStxtTLVf2sNzDrbabJPyVOpoM1qni0AC0AbNOSU4WS1JHxMIAELSOJEStQkckgpHSHaX0vpYJ4itm7CNqgIB6CWcOnQjTgA--tJuGZagvg4PaHCgApB1AvqgviR9ftHzIuRlxI_tZ9T6uRv758jVXnMHjff-CT7bfBBo68mmtPayco_vTmntQn-U_ePZex9v4zNeIJDAFfPQMYnei_lzIJnyvXwnpxBuvNaW1ppaYtgNIM_F-r8CBv6fu_IIPcV8mB08IrfLah_D1zQfgJOUZFwBNDCCFhaC-B4BrwKgiAiE-kHCm3gRGgfiSWzVQURgASWkwlWhwjgixh33tUC22D2jfn60_mILyFINKEnH9Dqk3GDy_3Zjnk8X1GyiQJsTSTMV3yUXlDsiVAMVg1SR8VMTmjtxqBwxNQvHyjnX2jCDnGXAiAsAsDJjd10x0BrG6AWAe2HB0HoDqGlDDTujplVCFEuAAG4gA

Steps to Reproduce

click

Current Behavior

Init echart with theme and no theme the color in chart is different

var myChart = echarts.init(chartDom, 'dark');
var myChart = echarts.init(chartDom);

Expected Behavior

The chart color when using theme the same as not using theme

var myChart = echarts.init(chartDom);

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response

slsn1g29

slsn1g291#

I made a minimal Reproduction from your example.

As you can see in there the part {..., color: ['#1890ff']} is the issue. A color property is not documented on setOption but it seems to set the color for all items in the plot. When using a theme this value is most likely overridden by the theme default values after it was initially set. Thats why its working with the "dark" theme.

If you remove the mentioned line the colors are equal for both themes:

option = {
  xAxis: {},
  yAxis: {},
  legend: {},
  series: [
    {
      type: 'scatter',
      name: 'A',
      data: [[1,2],[2,5],[7,1],[3,9],[6,8]]
    },
    {
      type: 'scatter',
      name: 'B',
      data: [[4,2],[3,5],[7,7],[4,6],[2,7]]
    },
    {
      type: 'scatter',
      name: 'C',
      data: [[4,5],[7,1],[5,3],[8,9],[6,2]]
    },
    {
      type: 'scatter',
      name: 'D',
      data: [[4,8],[7,5],[6,6],[3,2],[7,3]]
    }
  ],
  
  color: ['#1890ff'],  // <-- Remove this
};
rggaifut

rggaifut2#

I made a minimal Reproduction from your example.

As you can see in there the part {..., color: ['#1890ff']} is the issue. A color property is not documented on setOption but it seems to set the color for all items in the plot. When using a theme this value is most likely overridden by the theme default values after it was initially set. Thats why its working with the "dark" theme.

If you remove the mentioned line the colors are equal for both themes:

option = {
  xAxis: {},
  yAxis: {},
  legend: {},
  series: [
    {
      type: 'scatter',
      name: 'A',
      data: [[1,2],[2,5],[7,1],[3,9],[6,8]]
    },
    {
      type: 'scatter',
      name: 'B',
      data: [[4,2],[3,5],[7,7],[4,6],[2,7]]
    },
    {
      type: 'scatter',
      name: 'C',
      data: [[4,5],[7,1],[5,3],[8,9],[6,2]]
    },
    {
      type: 'scatter',
      name: 'D',
      data: [[4,8],[7,5],[6,6],[3,2],[7,3]]
    }
  ],
  
  color: ['#1890ff'],  // <-- Remove this
};

Yes, this is a reasonable explanation.

But I think the expected behavior should be the chart color when using theme, the same as not using theme .

option.color priority higher than theme

lf3rwulv

lf3rwulv3#

Currently the configured color option will be merged into the specified color in the theme options, instead of the whole replacement. For the color array, you only define 1 color, which is less than the number of theme color, so it finally only replaced the first color. (But I also feel that the merge strategy is a bit strange in this case)

相关问题