Angle incorrect while plotting with dimple.js - dimple.js

i am plotting a d3 chart.
The chart is given at http://dimplejs.org/examples_viewer.html?id=pie_matrix.
But when i plot the chart with my data in pie chart the total percentage is 99%. Not 100%.
var svg = dimple.newSvg("#ChartName", 590, 400);
var myChart = new dimple.chart(svg, data);
myChart.setBounds(95, 25, 475, 335);
var x = myChart.addCategoryAxis("x", "Month");
x.addOrderRule("mno");
myChart.addCategoryAxis("y", "AgeGroup");
var p = myChart.addMeasureAxis("p", "cnt");
p.tickFormat="02d";
var pies = myChart.addSeries("event", dimple.plot.pie);
pies.radius = 25;
myChart.addLegend(240, 10, 330, 20, "right");
myChart.draw();
Am using http://dimplejs.org/dist/dimple.v2.1.0.min.js.
Example while i plot, i get 50% not 50.00% , because of rounding of angle for plotting it is showing wrongly. Can you people please tell how to remove the round of.
The data from database is correct. It is a count like 100,200 etc.while plotting pie with that values it is showing wronly.
Example
--------
Count1 =562
Count2 =62
Count3 =53
Count4 =39
While Plotting with these values in pie chart i got Count1 = 78%, Count2 = 9%, Count3 = 7%, Count4 = 5%.
Total is 99%.Not 100%.
While finding percentage manually we get upto 2 spaces after .

Try setting the tick format after drawing, that way it won't interfere with the chart drawing but will affect the tooltip.

Related

Percentage labels in pie chart with ggplot

I'm working now in a statistics project and recently started with R. I have some problems with the visualization. I found a lot of different tutorials about how to add percentage labels in pie charts, but after one hour of trying I still don't get it. Maybe something is different with my data frame so that this doesn't work?
It's a data frame with collected survey answers, so I'm not allowed to publish them here. The column in question (geschäftliche_lage) is a factor with three levels ("Gut", "Befriedigend", "Schlecht"). I want to add percentage labels for each level.
I used the following code in order to create the pie chart:
dataset %>%
ggplot(aes(x= "", fill = geschäftliche_lage)) +
geom_bar(stat= "count", width = 1, color = "white") +
coord_polar("y", start = 0, direction = -1) +
scale_fill_manual(values = c("#00BA38", "#619CFF", "#F8766D")) +
theme_void()
This code gives me the desired pie chart, but without percentage labels. As soon as a I try to add percentage labels, everything is messed up. Do you know a clean code for adding percentage labels?
If you need more information or data, just let me know!
Greetings
Using mtcars as example data. Maybe this what your are looking for:
library(ggplot2)
ggplot(mtcars, aes(x = "", fill = factor(cyl))) +
geom_bar(stat= "count", width = 1, color = "white") +
geom_text(aes(label = scales::percent(..count.. / sum(..count..))), stat = "count", position = position_stack(vjust = .5)) +
coord_polar("y", start = 0, direction = -1) +
scale_fill_manual(values = c("#00BA38", "#619CFF", "#F8766D")) +
theme_void()
Created on 2020-05-25 by the reprex package (v0.3.0)

How to draw horizontal line from yesterdays high and close points? and how to solve time format? Fill between lines

I'm new here and i want to ask about my work. So I'm using this code for now but result is shown only full horizontal line not from the high from highestbars . How can i draw from exact highest price?
And im using time.session like "0000-0500" but this session in 1 exchange (broker)is different from other
exchanges. So how can I use same Session?
high = security(syminfo.tickerid, 'D', time[1], lookahead = barmerge.lookahead_on)
prevhigh = security(syminfo.tickerid, 'D', high[1], lookahead = barmerge.lookahead_on)
var high_line = line.new(x1 = high, x2 = right(extend_right), y1 = prevhigh, y2 = prevhigh, color = line_color, width = line_width, xloc = xloc.bar_time)
line.set_x1(high_line, high)
And can i fill between 2 lines which drawn by above code?
i used Line.set
Thank you.

how to draw lines in Pine script (Tradingview)?

Pine editor still does not have built-in functions to plot lines (such as support lines, trend lines).
I could not find any direct or indirect method to draw lines.
I want to build function that look like below (for example only)
draw_line(price1, time1,price2, time2)
any Ideas or suggestions ?
Unfortunately I don't think this is something they want to provide. Noticing several promising posts from 4 years ago that never came through. The only other way, seem to involve some calculations, by approximating your line with some line plots, where you hide the non-relevant parts.
For example:
...
c = close >= open ? lime : red
plot(close, color = c)
would produce something like this:
Then, you could try to replace red with na to get only the green parts.
Example 2
I've done some more experiments. Apparently Pine is so crippled you can't even put a plot in function, so the only way seem to be to use the point slope formula for a line, like this:
//#version=3
study(title="Simple Line", shorttitle='AB', overlay=true)
P1x = input(5744)
P1y = input(1.2727)
P2x = input(5774)
P2y = input(1.2628)
plot(n, color=na, style=line) // hidden plot to show the bar number in indicator
// point slope
m = - (P2y - P1y) / (P2x - P1x)
// plot range
AB = n < P1x or n > P2x ? na : P1y - m*(n - P1x)
LA = (n == P1x) ? P1y : na
LB = (n == P2x) ? P2y : na
plot(AB, title="AB", color=#ff00ff, linewidth=1, style=line, transp=0)
plotshape(LA, title='A', location=location.absolute, color=silver, transp=0, text='A', textcolor=black, style=shape.labeldown)
plotshape(LB, title='B', location=location.absolute, color=silver, transp=0, text='B', textcolor=black, style=shape.labelup )
The result is quite nice, but too inconvenient to use.
UPDATE: 2019-10-01
Apparently they have added some new line functionality to Pinescript 4.0+.
Here is an example of using the new vline() function:
//#version=4
study("vline() Function for Pine Script v4.0+", overlay=true)
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line, 54 lines maximum allowable per indicator
return = line.new(BarIndex, -1000, BarIndex, 1000, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)
if(bar_index%10==0.0)
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
As for the other "new" line function, I have not tested it yet.
This is now possible in Pine Script v4:
//#version=4
study("Line", overlay=true)
l = line.new(bar_index, high, bar_index[10], low[10], width = 4)
line.delete(l[1])
Here is a vertical line function by midtownsk8rguy on TradingView:
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line Function, ≈50-54 lines maximum allowable per indicator
// return = line.new(BarIndex, 0.0, BarIndex, 100.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and RSI, Stochastic, etc...
// return = line.new(BarIndex, -1.0, BarIndex, 1.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and +/-1.0 oscillators
return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=true)
if(bar_index%10==0.0) // Generically plots a line every 10 bars
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
You can also use if barstate.islast if you only draw your lines once instead of on each candle, this way you don't need to delete the previous lines.
More compact code for draw lines:
//#version=3
study("Draw line", overlay=true)
plot(n, color=na, style=line)
AB(x1,x2,y1,y2) => n < x1 or n > x2 ? na : y1 + (y2 - y1) / (x2 - x1) * (n - x1)
plot(AB(10065,10136,3819,3893), color=#ff00ff, linewidth=1, style=line,
transp=0)
plot(AB(10091,10136,3966.5,3931), color=#ff00ff, linewidth=1, style=line,
transp=0)
Here is an example that might answer the original question:
//#version=4
study(title="trendline example aapl", overlay=true)
//#AAPL
line12= line.new(x1=int(1656322200000),
y1=float(143.49),
x2=int(1659519000000),
y2=float(166.59),
extend=extend.right,
xloc=xloc.bar_time)
(to calculate the time it needs to be calculated as the *bar open time in unix milliseconds see: https://currentmillis.com/ ; can be calculated in excel with this formula =
= (([date eg mm/dd/yyyy]+[bar open time eg 9.30am])- 0/24 - DATE(1970,1,1)) * 86400000
= ((6/27/2022+9:30:00 AM)- 0/24 - DATE(1970,1,1)) * 86400000
= ((44739+0.395833333333333)- 0/24 - DATE(1970,1,1)) * 86400000
= 1656322200000
)
adjust the zero/24 to offset the time zone if needed eg 1/24

zedgraph common majortick for all y axis

I'm using Zedgraph to display multiple y axis (both YAxis and Y2Axis).
When having multple yaxis it becomes rather hard to compare curves with all the major ticks. On the picture below each curve has its own major tick:
https://dl.dropbox.com/u/70476173/problem.png
I would like the graph to share the same major ticks so that it is easy to compare the curves. I have tried with the code:
//majorTickCount = 12.0
var min = Math.Floor(yAxis.Scale.Min);
var max = Math.Ceiling(yAxis.Scale.Max);
var step = (max - min) / majorTickCount;
var wholeStep = step;
max = min + wholeStep * majorTickCount;
//yAxis.Scale.MajorStepAuto = true;
//yAxis.Scale.MajorStepAuto = false;
//yAxis.Scale.MinGrace = 0;
//yAxis.Scale.MaxGrace = 0;
yAxis.Scale.Min = min;
yAxis.Scale.Max = max;
yAxis.Scale.MajorStep = wholeStep;
yAxis.Scale.BaseTic = min;
This seems to create the desired effect, but with a problem:
https://dl.dropbox.com/u/70476173/problem2.png
The red curves 2nd and 3rd point has the value 6, but as you can see on the picture, the point lies below the majorgrid for 6. I believe the problem is that the majorstep is calculated to 2.5 and the y axis label displaying 6 should rather be 6.1 or something like that.
TL;DR: How do I make all my y axes share the same major steps
Any idea of how I can scale the y axis so that they share the same major grid?

how to draw the second curve based Y2axis while the first curve is based on YAxis?

I'm using ZedGraph.
I have 2 curves to draw, the first curve is based on the scale of YAxis, while the second one is based on the Y2Axis, the value in first curve is far bigger than the second value.
In my project, both curves are based on YAxis, which makes the graph ugly.
Does anyone has experience to draw second curve based on the Y2Axis?
Here is my code: (What should I change?)
PointPairList p1 = new PointPairList(),
p2 = new PointPairList();
//code to add data into p1 and p2
GraphPane gp = new GraphPane();
gp.AddCurve(p1, "", Color.Black);
gp.AddCurve(p2, "", Color.Blue);
gp.XAxis.Scale.Min = v1;
gp.Y2Axis.Scale.Max = v2;
gp.AxisChange();
gp.XAxis.Scale.IsUseTenPower = false;
gp.Y2Axis.Scale.IsUseTenPower=false;
Thank you.
If I want to set the Y2Axis share the same grid of Y1Axis, after:
LineItem curveY2 = gp.AddCurve(p2, "", Color.Blue);
...
curveY2 .IsY2Axis = true;
i.e., the grid is based on Y1Axis, then Y2Axis has the same grid but with different lable.
For example, Y1Axis is from 1 to 300, and have 7 rows, however Y2Axis has 1 to 20, I want the Y2Axis also have 7 rows (same as the Y1Axis), which function should I use?
LineItem curveY2 = gp.AddCurve(p2, "", Color.Blue);
...
curveY2 .IsY2Axis = true;
//If you have more than one axis on the related side, you have to assign the index of the axis
curveY2 .YAxisIndex = 0;