【问题标题】:dojox.charting: how to align the plotArea of 2 charts, one above another?dojox.charting:如何对齐 2 个图表的 plotArea,一个在另一个之上?
【发布时间】:2010-06-23 08:16:45
【问题描述】:

我正在尝试布局 2 个链接图表,一个在另一个之上,类似于您在 Google 财经页面上看到的。

我可以很好地渲染两个图表,但是让 plotAreas 准确排列有点神秘。每个图表的 chart.plotArea.width 似乎取决于我的 Y 轴标签的宽度。因此,这 2 个图表的宽度不同,chart.getCoord().l. 的值也不同

目前,我正在使用手动计算的偏移量,但一定有更好的方法。

 this.chart.render();  // top chart, getCoords().w=800

 // manually set margins for lower chart to match
 this.chartVol.margins.l = this.chart.offsets.l - 59 + 10;  
 this.chartVol.margins.r = this.chart.offsets.r - 31 + 10;

 // render bottom chart
 this.chartVol.render();  // bottom chart same width, getCoords().w=800

【问题讨论】:

    标签: dojo dojox.charting


    【解决方案1】:

    有两种简单的方法:

    1. 使用maxLabelSizelabelFunc。前者是以像素为单位的最大标签大小。后者是一个函数,它接受一个数字,并返回一个对应的字符串标签。
    2. 使用labels,它是{value, text} 对象的数组,并在末尾包含一个所需大小的长虚拟字符串和一些虚假值。

    我不记得没有自定义标签怎么做,所以如果你觉得真的需要它,请submit an enhancement ticket

    【讨论】:

    • 我尝试使用相同的虚拟字符串作为标签,但 plotAreas 仍然偏离了几个像素。问:maxLabelSize 的文档在哪里?它属于什么类 - 我尝试了 chart.addAxis('y',{maxLabelSize:5}) 但它似乎没有做任何事情。
    • A:目前在dojox/charting/axis2d/Default.js的源码中。关于您不成功的尝试: {maxLabelSize: 5) 是 5 像素。我怀疑这是不是这个想法。而且您必须将它与 labelFunc 一起使用。请参阅上面我的答案正文。
    猜你喜欢
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多