我正在努力缩放道场图表。 我的图表在javascript中定义如下:
var c2 = new dojox.charting.Chart("myChart");
c2.addPlot("default", {
type: "StackedAreas",
tension: 4
}).addAxis("x", {
labels : labels
}).addAxis("y", {
vertical: "true",
fixLower: "major",
fixUpper: "major"
}).setTheme(dojox.charting.themes.Tufte).addSeries("Series A", values).render();
然后,我有2个水平滑块,我想用它来缩放x轴的左右边界。为此,我做了类似的事情:
dojo.connect(myMinSlider, "onChange", function(value) {
var currentMin = Math.ceil(value),
currentMax = myMaxSlider.get('value'),
// currentMax and currentMin are the values of the left and right sliders
scale = theMaxValueOfMyXAxis / (currentMax - currentMin);
offset = currentMin; // this is wrong... should be in "data coordinates" but I don't know what data coordinates refers to...
c2.setAxisWindow("x", scale, offset, { duration: 500 }).render();
});
现在,缩放看起来不错,但偏移是完全错误的。 This tutorial说“偏移是在数据坐标中”,但我恐怕在这里没有得到“数据坐标”的含义。
假设myMinSlider值设置为35,我希望我的图形的X轴从35开始。这就是为什么我将它设置为currentMin值。但是,我的图表移动到Y轴的左侧......距离它的距离太远......
我的图表中的数据是一个如下所示的系列:
var data = [36,297,1202,205,160,130,122,121,120,111,116,65,118,123,118,104,144,114,141,216,134,216,89,89,103,95,85,95,93,101,103,98,96,116,119,129,112,104,107,103,86,100,107,81,117,96,105,115,115,116,129,117,116,127,129,121,125,118,133,128,128,136,110,142,152,144,162,154,154,134,148,166,140,168,154,158,177,186,169,210,202,230,232,237,226,251,298,313,410,469,614,765,982,1352,1796,2239,2806,3217,3800,4378,5083,5353,5728,6111,6000,6051,5901,5835,5569,5212,4736,4408,3816,3340,2782,2223,1909,1525,1218,1057,878,645,521,421,296,270,234,197,151,165,150,128,143,142,135,127,146,107,108,109,130,126,134,114,116,102,124,158,148,130,120,137,138,165,130,136,124,121,137,122,131,106,119,136,109,100,91,118,115,94,104,99,101,99,91,113,95,111,88,92,102,87,109,83,99,100,88,100,79,79,96,116,98,84,88,72,74,82,78,85,93,68,96,92,84,77,101,106,87,102,110,96,121,107,110,112,110,113,120,96,106,100,109,109,139,147,126,147,140,143,118,125,129,132,132,118,116,129,140,124,111,125,117,134,91,100,116,89,12]
有没有人有想法?
答案 0 :(得分:2)
据我所知你使用chart.setAxisWindow(name,scale,offset),例如
chart.setWindow(“x”, 3, 2)
chart.setWindow(“y”, 3, 1)
这会将X轴上的偏移设置为2,并将Y轴设置为1。
如果您想了解更多信息,请转到here
答案 1 :(得分:1)
似乎解决方案比我预期的要简单得多:
chart.zoomIn(thAxis, [newStart, newEnd]);