Plotly饼图重叠问题咨询:实现3列2行共6个饼图独立布局展示
修复方案
核心修改点如下:
- 修复数据结构错误:
data1多包裹了一层数组,和其他trace结构不一致导致渲染异常 - 为每个饼图新增
domain属性指定显示区域:饼图属于非笛卡尔坐标系图表,无法自动适配grid布局配置,需要通过x/y坐标范围单独控制每个饼的位置 - 调整画布参数适配3列2行的展示需求,可根据实际电视屏幕尺寸调整高度和边距
修改后的JS代码部分如下:
<% Set reasonRS = oConn.Execute("SELECT TOP (6) reason, reason_code,sum(qty) AS qty FROM [DCC].[dbo].vDCC_Remakes_Print WHERE create_date >= DATEADD(day,-30,GETDATE()) GROUP BY reason,reason_code ORDER BY sum(qty) DESC") if not reasonRS.EOF then i = 1 do until reasonRS.EOF Response.write (VbCrLf & VbCrLf) Response.write ("charttitle" & i & " = """& reasonRS("reason") & """") Response.write (VbCrLf) Response.write ("chartdata" & i & " = [") Set bomitemRS = oConn.Execute("SELECT TOP (8) bomitem, sum(qty) AS qty FROM [DCC].[dbo].DCC_Remakes WHERE datestamp >= DATEADD(day,-30,GETDATE()) AND reason="&reasonRS("reason_code")&" GROUP BY bomitem ORDER BY sum(qty) DESC") if not bomitemRS.EOF then x = "" y = "" do until bomitemRS.EOF x = x & bomitemRS("qty") & "," y = y & """" & bomitemRS("bomitem") & """" & "," bomitemRS.MoveNext loop end if ' subtract the last comma here ' x = left(x,len(x)-1) y = left(y,len(y)-1) Response.write(x) Response.write("]" & VbCrLf) Response.write("chartlabel" & i & " = [ " & y & " ]") reasonRS.MoveNext i = i + 1 loop end if %> var data1 = { values: chartdata1, labels: chartlabel1, type: 'pie', title: charttitle1, domain: {x: [0, 0.3], y: [0.6, 1]} }; var data2 = { values: chartdata2, labels: chartlabel2, type: 'pie', title: charttitle2, domain: {x: [0.35, 0.65], y: [0.6, 1]} }; var data3 = { values: chartdata3, labels: chartlabel3, type: 'pie', title: charttitle3, domain: {x: [0.7, 1], y: [0.6, 1]} }; var data4 = { values: chartdata4, labels: chartlabel4, type: 'pie', title: charttitle4, domain: {x: [0, 0.3], y: [0, 0.4]} }; var data5 = { values: chartdata5, labels: chartlabel5, type: 'pie', title: charttitle5, domain: {x: [0.35, 0.65], y: [0, 0.4]} }; var data6 = { values: chartdata6, labels: chartlabel6, type: 'pie', title: charttitle6, domain: {x: [0.7, 1], y: [0, 0.4]} }; var data = [data1, data2, data3, data4, data5, data6]; var layout = { height: 800, // 可根据实际电视屏幕分辨率调整数值 margin: {t: 20, b: 20, l: 20, r: 20} }; Plotly.newPlot('PiCharts', data, layout);
如果需要调整饼图之间的间距,直接修改每个domain里的x、y坐标边界数值即可。
内容的提问来源于stack exchange,提问作者Orshix
相关产品推荐
相关产品推荐

