Question

I'm struggling with the zooming on a dojo chart. My chart is defined in javascript like this :

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();

Then, I have 2 horizontal sliders which I want to use to zoom from the left and right bounds of my x axis. For that I do something like :

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();
});

Now, the scaling looks good, but the offset is totally wrong. This tutorial says that the "offset is in data coordinates", but I'm afraid I don't get the meaning of "data coordinates" here.

Say myMinSlider value is set to 35, I would expect my graph's X axis to start at 35. That's why I'm setting it to the currentMin value. However, my chart moves to the left of the Y axis... too far from what it should...

The data in my chart is a series that looks like this :

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]

Does anyone have an idea ?

Was it helpful?

Solution 2

It seems like the solution is much simpler than what I expected :

chart.zoomIn(thAxis, [newStart, newEnd]);

OTHER TIPS

As far as I know you use chart.setAxisWindow(name, scale, offset), for example

chart.setWindow(“x”, 3, 2)
chart.setWindow(“y”, 3, 1)

This will set the offset on the X-axis by 2 and on the Y-axis by 1.

If you want to know more about it gohere

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top