面对各种定制,echarts图表有时候不好处理,无论是数据处理还是样式处理,都会被echarts限制。
举例:echarts散点图如果数据较少,echarts会均匀分布,如图1

对于产品或者老板对页面的要求,认为中间空的太多,要求如果x轴的数据较少时,依次排开,如果用echarts的xAxis.max,只要数据中的 X 值超过了它,那么图表会自动扩展 X 轴范围,不能固定范围

直接看效果图

前端用的vue,数据结构仅供参考,可以自行修改
<div class="sku-supplier-chart">
<div class="chart-count">Count</div>
<div class="chart-yAxias">
<div
class="y-item"
v-for="(item, index) in maxSupllierCount + 1"
:key="index"
:style="{
bottom: `calc(${(index * 100) / maxSupllierCount}% - 12px)`,
}"
>
{
{ index }}
</div>
</div>
<div class="chart-content">
<div
class="item-line"
:style="{ width: itemLineWidth + 'px' }"
v-for="(item, index) in skuList"
:key="index"
>
<template v-for="(dropItem, dropIndex) in item.supplierList">
<el-popover
:key="dropIndex"
placement="top-start"
:title="item.productNo"
width="230"
trigger="hover"
content=""
>
<p>
<span style="font-weight: bold"
>{
{ currentDropItem.companyName }}: </span
><span>{
{ currentDropItem.unitPrice }} </span>
<span>{
{ currentDropItem.unitPriceLov }}</span>
</p>
<div
slot="reference"
class="item-drop"
:key="dropIndex"
:style="{
bottom: `calc(${
(100 / maxSupllierCount) * (dropIndex + 1)
}% - 6px)`,
backgroundColor: dropItem.hexColor,
}"
@mouseover="mouseoverDropItem(dropItem)"
@mouseout="mouseoutDropItem(dropItem)"
></div>
</el-popover>
</template>
<div class="sku-title">
<span>{
{ item.productNo }}</span>
</div>
</div>
</div>
</div>
data(){
return{
skuList: [
{
rfqNo: "Test2304040004",
productNo: "Test0430SKU0430SKU0",
productName: "Mutton",
rfqProQty: 1,
supplierList: [
{