Is there any way to add gridlines to a gRaphael line chart? - raphael

I have a line chart that I've created with gRaphael. It has axes and tick marks, but I'd like to have grid lines. Is there built-in way to achieve this or an add on library that can help me?

gRaphael does not have a built-in way to add grid lines, but it is pretty easy to draw them, either by editing the source code or manipulating your graph object after you create it.
I had found an extension called RaphAlytics and used its drawGrid() function in cases where I needed a bounding box with a grid.
You can adapt this function for any gRaphael graph as needed to draw gridlines. On a line chart, I needed to draw horizontal gridlines that were aligned with the left axis marks on a line chart, so I used the function as an example like this:
// Draw horizontal gridlines
for (var i = 0; i < g.axis[1].text.items.length; i++) {
r.path(['M', x, g.axis[1].text.items[i].attrs.y, 'H', w + x]).attr({
stroke : '#EEE'
}).toBack();
}
Here's a working fiddle to illustrate that example: http://jsfiddle.net/KM3BB/1/

I tried doing this yesterday. Short answer: gRaphaël can't do this for you with any linechart options nor axis options, you have to do-it-yourself with Raphaël.
Something like:
var r = Raphael("holder"), txtattr = { font: "12px sans-serif" };
r.path('M 15 200.5 L 310 200.5 M 15 180.5 L 310 200.5');
r.linechart(10, 10, 300, 220, x, [y, y2, y3]);
This means under my linechart draw a path which starts from 15,200.5 and draws a straight line to 310,200.5 moves to 15,180.5 and draws a line to 310,180.5. Don't ask me why but the .5 is important for getting the stroke to actually be 1px wide and solid black. Otherwise it seems to get aliased to 2px wide at 50% opacity. You have to calculate the exact placement in regards to your linechart yourself.
You can also play with the path function in the playground by changing r to paper.
You might also consider looking at Google Chart Tools if your looking for things like defining the exact range of the axis (as opposed to just the min and max of the input).

Related

tkinter canvas create_arc method giving round edged arcs

I am drawing arcs in tkinter. They use the 'arc' method so only have an outer edge of a specified width and colour. Annoyingly some arcs seem to have randomly have a rounded edge. Does anyone know if this is a bug or if it can be fixed?
Example code:
w1.create_arc(xarc0,yarc0,xarc1,yarc1,start=arcstart,extent=arcextent,width=thick1,outline=mc,style="arc")
Pic of the problem attached.
After some experimenting, I believe this is a glitch
I ran a simulation to create 360 arcs, each with an extent from 1 - 360, I found that the only time when the arc has a curved end was when the extent of the arc was 90 or 271, I don't know why this happens but I don't think its supposed to.
The green arc is the simulation, the red and the blue arc are the arcs which have a curved end. I don't think there is a way to fix this problem, however you can change the extent from 90 to 91 as I've done for the orange arc, as you can see it has a straight end and there's not much difference.
Here's the code if you want to play around with it:
from tkinter import *
Window = Tk()
w1 = Canvas(Window)
w1.pack()
for x in range(360):
w1.after(5)
arc = w1.create_arc(20, 20, 150,100,start=0,extent=x,width=30,outline = "green", style="arc")
w1.update()
if x == 90 or x == 271:
print("Now!")
w1.create_arc(160,20, 300,100,start=0,extent=90,width=30,outline = "red", style="arc")
w1.create_arc(180,120, 320,200,start=0,extent=271,width=30,outline = "blue", style="arc")
w1.create_arc(0, 150, 140,230,start=0,extent=91,width=30,outline = "orange", style="arc")

limit the Y-axis character in google visulaization combo graph to given limit

Hi,
Is there any way to limit the Y-axis character in google visulaization combo graph to given limit and then ...
By Default it is doing when more then 22 character. But I want to reduce it to given character.
Attached is the screen shot
I assume you meant X-axis, not Y-axis, given your screen shot. There is a quick-and-dirty approach that truncates the displayed strings to 22 characters, but this will affect the tooltips as well as the axis labels:
for (var i = 0; i < data.getNumberOfRows(); i++) {
// assumes column 0 is your labels
var label = data.getValue(i, 0);
label = label.substring(0, 22);
data.setFormattedValue(i, 0, label);
}
If you just want to affect the axis labels, there are different approaches you can take, and which one you take depends on what you want to achieve by truncating the labels. What is it that you want to achieve?

MSChart HowTo Create a Second CursorX to have multiple Cursor by a second Transparant ChartArea?

I am try to introduce a Second CursorX at AxisX Primary if this is possible some how?
I did try to activate a second CursorX at Secondary but that one did not work as expected,
I also readed about Line Annotation and Vertical Line Annotation and created some kind of line but a Second set of CursorX CursorY would be far nicer
I did try to create and as much as empty as possible and Transparant Second ChartArea which i try to overlay on top of the ChartArea1, i noticed InnerPlotPosition and Postion of both ChartArea should stay in track to get a full aligned Overlay, and next the CursorX of second ChartArea should be displayed on top of ChartArea1
This is what i think how it could be done but don't have a clue if it sounda for a good way to create a second CursorX maybe Line Annotation is an easier road to rome
Any help suggestion are welcome
Thanks in advance
Suppose your chart contains multiple chart areas aligned vertically, below code allows you set CursorX in each chart area:
Dim c1 As New Chart
'...here code block to build each chart area ...
'...then use below sample code to align each chart area vertically:
'c1.ChartAreas(i).AlignmentOrientation = AreaAlignmentOrientations.Vertical
'c1.ChartAreas(i).AlignWithChartArea = c1.ChartAreas(0).Name
'below set horizontal cursor (it is a gold vertical bar in each chart area):
For Each area As ChartArea In c1.ChartAreas
area.CursorX.LineColor = Color.Gold
area.CursorX.LineWidth = 3
area.CursorX.IsUserEnabled = True
area.CursorX.IsUserSelectionEnabled = True
area.CursorX.SelectionColor = System.Drawing.Color.PaleGoldenrod
Next

SetViewBox moving the paper

I am using the setViewBox() function in Raphael 2. The width and height is multiplied by a value like (1.2, 1.3 ...). This changes the magnification/ zooming properly but the x and y which I have given as 0,0 makes the paper display its contents after some offset. If i modify the x and y to some positive value after the rendering( using firebug!!) then the top left of the paper moves back and above to its right position. I want to know how will the value be calculated. I have no idea about how the x,y affect the viewbox. If anybody can give me any pointers for this it will be a real help.
I have tried giving the difference between the width/ height divided by 2. Also I must mention that I am not rendering an image but various raphael shapes e.g. rects, paths text etc. in my paper.
Looking forward to some help!
Kavita
this is an example showing how to calculate the setViewBox values, I included jquery (to get my SVG cocntainer X and Y : $("#"+map_name).offset().left and $("#"+map_name).offset().top) and after that I calculated how much zoom I need :
var original_width = 777;
var original_height = 667;
var zoom_width = map_width*100/original_width/100;
var zoom_height = map_height*100/original_height/100;
if(zoom_width<=zoom_height)
zoom = zoom_width;
else
zoom = zoom_height;
rsr.setViewBox($("#"+map_name).offset().left, $("#"+map_name).offset().top, (map_width/zoom), (map_height/zoom));
did you put the center of your scaling to 0,0 like:
element.scale(1.2,1.2,0,0);
this can scale your element without moving the coordinates of the top left corner.

google charts api : wrong axis with LXY chart?

I'm trying to display some very simple data using Google Charts API.
My data are a serie of X,Y points:
(1,44) (2,46) (3,46) (4,43) (5,46) and (6,44).
X-axis : from 0 to 300, step 50
Y-axis : from 1 to 50, step 5
I should end up with a line almost in the top, to the left, of the chart (43-46 are near 50).
But here is what I get:
URL = http://chart.apis.google.com/chart?cht=lxy&chs=500x300&chd=t:1,2,3,4,5,6|44,46,46,43,46,44&chxt=x,y&chxr=0,0,300,50|1,0,50,5
If I change Y-axis, 1 to 100 (instead of 50), it's ok...
URL = http://chart.apis.google.com/chart?cht=lxy&chs=500x300&chd=t:1,2,3,4,5,6|44,46,46,43,46,44&chxt=x,y&chxr=0,0,300,50|1,0,100,5
I'm probably mistaking, but I can't find what is wrong.
If you add data scale the chart does show correctly.
http://chart.apis.google.com/chart?cht=lxy&chs=500x300&chd=t:1,2,3,4,5,6|44,46,46,43,46,44&chxt=x,y&chxr=0,0,300,50|1,0,50,5&chds=0,300,0,50