echarts [Feature] Example of color separation by category with encode

5jdjgkvh  于 3个月前  发布在  Echarts
关注(0)|答案(3)|浏览(68)

What problem does this feature solve?

Coming from vega-lite, I'm trying to render a bar chart that splits the bars by category. Currently I find myself having to transform my data in order to send it to the chart series.

Playing with the axis encode I sort of get the result I'm looking for: https://codesandbox.io/s/funny-shadow-hbsjsm?file=/src/App.tsx if you hover over the bars you will see its actually rendering the proper values and bar sizes split by categories but all with the same color and no separation.

Is this kind of behavior not supported yet?

What does the proposed API look like?

series: {
            type: "bar",
            showBackground: true,
            dataGroupId: "source_dtg",
            seriesLayoutBy: "column",
            colorBy: "data", => support coloring by a field 
            splitBy: "categories" => new option to split by a category
            encode: {
              tooltip: ["categories", "source_dtg", "count"],
              // Map the "date" column to X axis.
              x: "source_dtg",
              // Map the "count" column to Y axis
              y: "count",
            }
          }
ehxuflar

ehxuflar1#

Do you mean you want to use ECharts to get this?

Set barGap to be 0 should work.

lrpiutwd

lrpiutwd2#

Yes, I want to achieve this result. According to the docs barGap affects multiseries.

In my sandbox you can see I want to achieve this with only 1 series, not a multiseries. A multiseries means I have to get from my data how many bar series I need which can be expensive.

I can see that echarts is getting halfway there with what I have, you can see in this 2 screenshots how its clearly getting the proper information out of my data, rendering and overlapping the bars.

What I don't know if its supported is to actually make the bars background by category (or any field) and move them so they don't overlap

n1bvdmb6

n1bvdmb63#

You need barGap: 0, barCategoryGap: 0 .

相关问题