madlogos / recharts Goto Github PK
View Code? Open in Web Editor NEWThis project forked from yihui/recharts
An R Interface to Baidu ECharts2 Library
Home Page: http://madlogos.github.io/recharts
License: Other
This project forked from yihui/recharts
An R Interface to Baidu ECharts2 Library
Home Page: http://madlogos.github.io/recharts
License: Other
如题,做雷达图不应该先定义每个轴的最大最小值吗?不知道recharts能否做到?目前貌似在文档里没看到有相应接口
`server.R
library(shiny)
library(shinydashboard)
library(DT)
library(recharts)
server <- function(input, output,session) {
normal_data <- reactive({
normal_data<-data.frame(date=c( "2017-05-03" ,"2017-05-04" ,"2017-05-05" ,"2017-05-06", "2017-05-07" ,"2017-05-08" ,"2017-05-09", "2017-05-10", "2017-05-11", "2017-05-12"),
gmv=c(624209 ,472624, 399328, 375413, 361946 ,539620, 445253, 514724 ,656519 ,484356),
paid=c(593060 ,442278, 362852, 349019 ,336858 ,506433, 414796 ,463171 ,595089, 443657)
)
normal_data<-subset(normal_data,date>=as.Date(input$daterange[1]) &date<=as.Date(input$daterange[2] ))
normal_data<-as.data.frame(normal_data)
normal_data
})
output$normal_data <-
renderDataTable({
DT::datatable(normal_data(),rownames=F,extensions = 'FixedHeader',options = list(
fixedHeader=TRUE,bSort = T,bAutoWidth = T,bProcessing = F,pageLength = 9,
lengthMenu = list(c(9,-1),c('9','All')),
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Chinese.json')))
})
output$plot1 <-renderEChart({
normal_data<-normal_data()
p<- echart(
list(
title = list(text = 'GMV & PAID',subtext="GMV AND PAID SALES",x="center",y="top"),
tooltip = list(show=TRUE, trigger = 'axis',axisPointer=list(type="cross")),
legend = list(orient="horizontal",y='bottom',data = c('GMV','PAID'),selected=list('GMV'=TRUE,'PAID'=FALSE)),
xAxis = list(type = 'category',data =normal_data$date,axisLine=list(lineStyle=list(color='Black',width=1)),splitLine = list(show = FALSE)),
yAxis = list(list( type = 'value', splitLine = list(show = FALSE) ,position="left", axisLine=list(show=FALSE,lineStyle=list(color='Black',width=1)))),
series = list(list( type = 'line',name="GMV",data =normal_data$gmv,itemStyle = list(normal = list(color = 'DarkRed', label = list(show = TRUE)))),
list( type = 'line',name="PAID",data =normal_data$paid,itemStyle = list(normal = list(color = 'Black', label = list(show = TRUE))))
)
)
, width = 1000, height = 400)
print(p)
})
}
ui.R
library(shiny)
library(shinydashboard)
library(DT)
library(recharts)
ui <- dashboardPage(
header <- dashboardHeader(title="Just For Test",titleWidth = 250),
sidebar <- dashboardSidebar(
width=250,
sidebarMenu(
id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
)
),
body <- dashboardBody(
tabItems(
tabItem("dashboard",
eChartOutput("plot1",width = "100%", height = "300px"),
fluidRow(dateRangeInput("daterange","Daterange Select:",start = as.Date('2017/5/3'),end=as.Date('2017/5/12'),min=as.Date('2017/5/3'),max=as.Date('2017/5/12'))),
fluidRow(dataTableOutput("normal_data"))
)
)
))
`
看了下函数区别有点大
if (!require(devtools)) library(devtools)
install_github("madlogos/recharts")
Installation failed: there is no package called ‘curl’
新手小白请问这是什么原因
HI,能加入这个项目吗?
我现在在做一些可视化的工作,也试了些工具,感觉echart的工具比较多,风格也比较统一。
同样的数据,保存为xlsx后用xlsx包读取后绘图完全没有问题,但是数据量大的情况下xlsx就有些慢了,于是改用data.table包,但是用fread读取数据后,无法画图,报错内容是:
Error in [.data.table
(data, , j) :
j (the 2nd argument inside [...]) is a single symbol but column name 'j' is not found. Perhaps you intended DT[,..j] or DT[,j,with=FALSE]. This difference to data.frame is deliberate and explained in FAQ 1.1.
请问如何解决?
按照用例出现如下问题
echartr(iris, x=Sepal.Width, y=Petal.Width)
Error in eval(expr, envir, enclos) : object 'width_sum_.' not found
@miluylin commented on Tue Jun 13 2017
I'm new for JS but would like to change the original format to new format at the top of K chart as below. Would you please let me know how to modify the tooltip in K chart?
orignal format is
2017-06-13
Open開盤 :xxxx
High最高:xxxx
Close收盤:xxxx
Low最低:xxxx
new format is
2017-06-13 Open:xxxx | High:xxxx | Close:xxxx | Low最低:xxxx
so I try to modifiy the formatter in few ways.
1. copy the JS add " "
formatter = "function (params) {
var res = params[0].name;
for (var i = 0, l = params.length; i < l; i++) {
res += ' | ' + ' : ' + params[i].value;
}
}"
formatter = JS('function(params) {
${params[0].seriesName}:${params[0].value} |
${params[1].seriesName}:${params[1].value} |
${params[2].seriesName}:${params[2].value} |
${params[3].seriesName}:${params[3].value} |
')
formatter=JS('function (params) {
return params.seriesName +
"| Open : " + params.value[0] +
"| Close : " + params.value[1] +
"| Low : " + params.value[2] +
"| High : " + params.value[3]; }')
Thanks
@madlogos commented on Wed Jun 14 2017
This should be under recharts instead of recharts2.
Previously I did not include a high-level method to modify formatter. Now I just released a patch to GitHub to fix it. You can try it out.
Build an instance following the example:
g <- echartr(stock, as.character(date), c(open, close, low, high), type='k') %>%
setXAxis(name='Date', axisLabel=list(rotate=30)) %>%
setYAxis(name="Price")
By cat(g$x$tooltip$formatter)
, you will see the default tooltip for K chart:
function (params) {
var res = params[0].name;
res += "<br/>Open开盘 : " + params[0].value[0] +
"<br/>High最高 : " + params[0].value[3];
res += "<br/>Close收盘 : " + params[0].value[1] +
"<br/>Low最低 : " + params[0].value[2];
return res;
}
So then:
g %>% setTT(formatter=JS('function (params) {
var res = params[0].name;
res += " Open: " + params[0].value[0] +
" | High: " + params[0].value[3];
res += " | Close: " + params[0].value[1] +
" | Low: " + params[0].value[2];
return res;
}'))
If you don't want to re-install recharts, you can simply modify the object g in low-level manner:
g$x$tooltip$formatter <- JS(...)
@miluylin commented on Thu Jun 15 2017
非常感激. Thank you
Yiying Wang,
您好,谢谢您对recharts包的开发。
目前用于shiny时,发现了如题目所述的问题。
selectInput("dataset", "选择:", choices = c("A","B“,“C”,"D"))
choices选项为英文和数字都可以顺利跑出,
而
selectInput("dataset", "选择:", choices = c("名字A","名字B“,“名字C”,"名字D"))
时,选项无法与图形联动。
请教您原因和解决办法,谢谢您!
Hi,
I've defined a custom dataset.
But for some reason, when I click the node symbols, no details are shown.
Did I miss something?
Your help is much appreciated!
library(shiny)
library(recharts)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
actionButton("testBtn","Click")
,eChartOutput("lineChart")
)
)
)
server <- function(input, output) {
testResult <- eventReactive(input$testBtn,{
name <- c("wuhan","chongqing","wuhan","chongqing")
iter <- c(1,1,2,2)
values <- c(10,11,8,14)
tet <- data.frame(name,iter,values)
tet
})
output$lineChart <-
renderEChart(
echartr(testResult(), iter, values, name, type='line') %>%
setTitle('NY Temperature May - Sep 1973, by Month') %>%
setSymbols('emptycircle')
)
}
shinyApp(ui = ui, server = server)
楼主您好,我想使用echarts在shiny中做数据展现。可是直接在server.R中写如下:
output$myplot <- renderPlot({
echartr(iris, Sepal.Length, Sepal.Width, series = Species)
})
在ui.R中写如下:
mainPanel(
plotOutput('myplot')
)
页面上是空白。请问有没有可以提供的example?万分感谢!!!
另,建议您在echarts的教程中添加相关shiny的例子
正在写一个Shiny App,使用到了Line Chart, 但是作图后发现默认的tooltips 没有正常显示,原来是在X轴上垂直的指向线变成了Y轴,而且气泡只显示一个小球并没有显示应有的数值。我突然发现在您的在线文档
https://madlogos.github.io/recharts/Widget_01_Axis_cn.html 的这篇例子里面也有这个问题,如下图:
,不知是否是个BUG
@madlogos ,Hi,
很抱歉我又来打扰您了。。。
昨天在shiny中用你的包画recharts图时,发现shiny输入变化后,上一幅图的输出的结果还在,代码如下:
library(recharts)
library(shiny)
shinyApp(
ui = fluidPage(
numericInput('n','n',10,10,500),
eChartOutput('myChart')),
server = function(input, output) {
output$myChart = renderEChart({
echartR(data.frame(x = rnorm(input$n), y = rnorm(input$n)), x, y)})
}
)
如题所述,我想做一个网站页面热力图,想自定义热力图的图片
柱状图的数据每一位数字后都带了逗号,传入是double型数据
如下的Rmd:
---
title: "Untitled"
output: html_document
---
```{r}
library(recharts)
echart(iris, ~ Sepal.Length, ~ Sepal.Width)
报错:
pandoc: Could not fetch ~/R/x86_64-redhat-linux-gnu-library/3.4/recharts/htmlwidgets/lib/echarts/scatter.js ~/R/x86_64-redhat-linux-gnu-library/3.4/recharts/htmlwidgets/lib/echarts/scatter.js: openBinaryFile: does not exist (No such file or directory) 错误: pandoc document conversion failed with error 67 停止执行
为什么要去找scatter.js这个文件,
PS直接在R中运行时正常的
安装的时候出现这样的问题
Downloading GitHub repo madlogos/recharts@master
from URL https://api.github.com/repos/madlogos/recharts/zipball/master
Installing recharts
"d:/Program Files/R/R-3.3.2/bin/x64/R" --no-site-file --no-environ --no-save
--no-restore --quiet CMD INSTALL
"C:/Users/aresren/AppData/Local/Temp/RtmpINoq5T/devtools33c28f3c29/madlogos-recharts-ab0bdfc"
--library="d:/Program Files/R/R-3.3.2/library" --install-tests
'd:\Program' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
Error: Command failed (1)
Yiying Wang,您好,
非常感谢您在recharts包的开发上做出的贡献,这个包让R用户仅使用dataframe就能够轻松画出各种echarts图,真的非常赞!!
这里想请教您一个问题,在使用echartr函数画仪表盘图(gauge)时,代码会自动将20%和80%的临界值设为分割点,并用不同的颜色表示0到20%,20%到80%,80%到100%三个区间的值。那么请问能否自定义分割点呢,比如,我想设为50%和80%(或者甚至更多的分割点)?
我记得之前看到过一篇文章“Function echartR with package recharts”(这篇文章的作者应该也是您吧),里面使用echartR函数绘制gauge图时,是可以自己定义分割点的。在您新开发的这个版本上,貌似这个功能没有了。。。
希望您能够回复我的疑问,感谢!
2017祝好~
Yiying Wang,您好!
这个包是用过的对echarts封装最顺畅的一个,谢谢您的开发~
目前想画一个**城市级别的热力图,仔细找了但是没有找到,不知道目前的这个版本有没有这个功能?望指教~
目标是希望在china_map中记入heatmap的时间序列变化
echartr(data = pm25.gps.monthly, lng = lng, lat = lat, y = PM2.5平均值, t = 时间, type = c("china_map")) %>% addHeatmap(data = pm25.gps.monthly, t = 时间, mode = "overide")
运行报错,找不到时间
这个变量。 去掉t参数,数据会被加总到一起,而不是分时间展现。
@jeremy001 commented on Fri Jul 14 2017
hello,
I use reharts to plot a stack bar chart, the R code is below:
echartr(data = duration_distribution,
x = pay_date,
y = order_num,
series = duration_class,
type = 'vbar',
subtype = 'stack')
but I get nothing in the Viewer tab on Rstudio:
Did anyone meet the same problem before?can anyone give me some help,thanks very much!!
@madlogos commented on Mon Jul 17 2017
This is not a recharts2 issue. it's a recharts issue. Please go to https://github.com/madlogos/recharts/issues
Since bar charts in recharts2 library does not support time x-axis, you should coerce pay_date to characters.
library("recharts", lib.loc="~/R/win-library/3.4")
echartr(iris, Sepal.Length, Sepal.Width, series = Species)
Error in echartr(iris, Sepal.Length, Sepal.Width, series = Species) :
could not find function "echartr"
echartr(mydata_count_prov, NAME, 病例数, type="map_china") %>% addHeatmap(data=mydata_count_town[,2:4], blurSize = 20, minAlpha=0.035,opacity=0.8) %>%
setTitle("") %>%
setTheme('dark')
@miluylin commented on Mon Jun 05 2017
Q: 請問 要怎麼設定 k chart的顏色 ?
看錯誤訊息 是目前 setSeries 沒有支持 type = 'k'
Error in match.arg(lst$type, validTypes) :
'arg' should be one of “line”, “bar”, “scatter”, “pie”, “radar”, “chord”, “force”, “map”, “gauge”,...
對照在JS裡面的架構與參數 不那麼直覺對應到 R 的參數
series : [
{
name:'上证指数',
type:'k',
barMaxWidth: 20,
itemStyle: {
normal: {
color: 'red', // 阳线填充颜色
color0: 'lightgreen', // 阴线填充颜色
lineStyle: {
width: 2,
color: 'orange', // 阳线边框颜色
color0: 'green' // 阴线边框颜色
}
},
emphasis: {
color: 'black', // 阳线填充颜色
color0: 'white' // 阴线填充颜色
}
},
能有辦法直接看 Echart的JS範例就可以對應寫成以下這樣嗎?
setSeries(type = "k", itemStyle = list( normal = list( color = "red",
color0 = "lightgreen",
lineStyle = list(width = 2,
color ='red',
color0= 'green'),
emphasis = list(color= 'black',
color0= 'white'))
@madlogos commented on Sun Jun 11 2017
十分抱歉,因为k线图没有通用属性以外的特殊属性,所以写完通用部分就忘了配置了。已经更新0.2-1。
PS: 应当是recharts,不是recharts2。recharts2目前应该还不能顺利跑通。
@miluylin commented on Mon Jun 12 2017
@madlogos 非常感謝
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.