xiaolin3303 / wx-charts

微信小程序图表库,Charts for WeChat Mini Program
MIT License
4.92k stars 1.67k forks source link

参数说明 - wxCharts使用文档 #56

Open xiaolin3303 opened 7 years ago

xiaolin3303 commented 7 years ago

参数说明

opts Object

opts.canvasId String required 微信小程序canvas-id

opts.width Number required canvas宽度,单位为px

opts.height Number required canvas高度,单位为px

opts.background String canvas背景颜色(如果页面背景颜色不是白色请设置为页面的背景颜色,默认#ffffff

opts.enableScroll Boolean 是否开启图表可拖拽滚动 默认false 支持line, area图表类型(需配合绑定scrollStart, scroll, scrollEnd方法)

opts.title Object (only for ring chart)

opts.title.name String 标题内容

opts.title.fontSize Number 标题字体大小(可选,单位为px)

opts.title.color String 标题颜色(可选)

opts.title.offsetX Number 标题横向位置偏移量,单位px,默认0

opts.subtitle Object (only for ring chart)

opts.subtitle.name String 副标题内容

opts.subtitle.offsetX Number 副标题横向位置偏移量,单位px,默认0

opts.subtitle.fontSize Number 副标题字体大小(可选,单位为px)

opts.subtitle.color String 副标题颜色(可选)

opts.animation Boolean default true 是否动画展示

opts.legend Boolen default true 是否显示图表下方各类别的标识

opts.type String required 图表类型,可选值为pie, line, column, area, ring, radar

opts.categories Array required (饼图、圆环图不需要) 数据类别分类

opts.dataLabel Boolean default true 是否在图表中显示数据内容值

opts.dataPointShape Boolean default true 是否在图表中显示数据点图形标识

opts.disablePieStroke Boolean default false 不绘制饼图(圆环图)各区块的白色分割线

opts.xAxis Object X轴配置

opts.xAxis.gridColor String 例如#7cb5ec default #cccccc X轴网格颜色

opts.xAxis.fontColor String 例如#7cb5ec default #666666 X轴数据点颜色

opts.xAxis.disableGrid Boolean default false 不绘制X轴网格

opts.xAxis.type String 可选值calibration(刻度) 默认为包含样式

opts.yAxis Object Y轴配置

opts.yAxis.format Function 自定义Y轴文案显示

opts.yAxis.min Number Y轴起始值

opts.yAxis.max Number Y轴终止值

opts.yAxis.title String Y轴title

opts.yAxis.gridColor String 例如#7cb5ec default #cccccc Y轴网格颜色

opts.yAxis.fontColor String 例如#7cb5ec default #666666 Y轴数据点颜色

opts.yAxis.titleFontColor String 例如#7cb5ec default #333333 Y轴title颜色

opts.yAxis.disabled Boolean default false 不绘制Y轴

opts.extra Object 其他非通用配置项

opts.extra.ringWidth Number ringChart圆环宽度,单位为px

opts.extra.lineStyle String (仅对line, area图表有效) 可选值:curve曲线,straight直线 (default)

opts.extra.column Object 柱状图相关配置

opts.extra.column.width Number 柱状图每项的图形宽度,单位为px

opts.extra.legendTextColor String 例如#7cb5ec default #cccccc legend文案颜色

opts.extra.radar Object 雷达图相关配置

opts.extra.radar.max Number, 默认为series data的最大值,数据区间最大值,用于调整数据显示的比例

opts.extra.radar.labelColor String, 默认为#666666, 各项标识文案的颜色

opts.extra.radar.gridColor String, 默认为#cccccc, 雷达图网格颜色

opts.extra.pie Object 饼图、圆环图相关配置

opts.extra.pie.offsetAngle Number, 默认为0, 起始角度偏移度数,顺时针方向,起点为3点钟位置(比如要设置起点为12点钟位置,即逆时针偏移90度,传入-90即可)

opts.series Array required 数据列表

数据列表每项结构定义

dataItem Object

dataItem.data Array required (饼图、圆环图为Number) 数据,如果传入null图表该处出现断点

dataItem.color String 例如#7cb5ec 不传入则使用系统默认配色方案

dataItem.name String 数据名称

dateItem.format Function 自定义显示数据内容

javarcn commented 7 years ago

当数据量大的时候,线图的x轴就相当密集,是否可以像echarts/highCharts那样设置横轴的数据显示比例呢,让x轴不那么密集?

xiaolin3303 commented 7 years ago

@javarcn 对于X轴很密集的情况工具会自动进行抽稀处理,如果还不能满足你的需求,关注下这个issue51

Galen-Yip commented 7 years ago

@xiaolin3303 自动抽稀的条件是?

xiaolin3303 commented 7 years ago

@Galen-Yip X轴显示文案不发生碰撞

wangsz111 commented 7 years ago

可以修改折线图转点处的颜色吗?比如:我在2016.6月有一个数据为空,按照目前的是不画折线图,但是,我的需求是,当数据为空时,我让折线处的颜色变成红色,而数值变成前后数值的算术平均数.请问这个可以实现吗?

wfq1095745112 commented 7 years ago

那个柱状图的 柱子怎么弄成圆角柱子

nanchaodong commented 7 years ago

请问柱状图怎么去掉x轴显示的文案

nanchaodong commented 7 years ago

请问 柱形图之间的间距怎么修改

xiaolin3303 commented 7 years ago

@wfq1095745112 暂时不支持圆角

xiaolin3303 commented 7 years ago

@nanchaodong opts.dataLabel Boolean default true 是否在图表中显示数据内容值 opts.extra.column.width Number 柱状图每项的图形宽度,单位为px 这些文档里面都有写

wj3284 commented 7 years ago

@xiaolin3303 请问,饼图的图例可以放到顶部或者左边或者右边吗?

nanchaodong commented 7 years ago

@nanchaodong opts.dataLabel Boolean default true 是否在图表中显示数据内容值 opts.extra.column.width Number 柱状图每项的图形宽度,单位为px 这些文档里面都有写 我问的是柱子与柱子之间的距离 不是改柱子的宽度 我发现调完柱子的宽度 并没有改变距离

nanchaodong commented 7 years ago

微信小程序布局中有雷达环形柱状图 这些图标的位置都不固定 页面上乱排布 为什么?

xiaolin3303 commented 7 years ago

@nanchaodong

微信小程序布局中有雷达环形柱状图 这些图标的位置都不固定 页面上乱排布 为什么?

这个问题请单独开一个issue,并附上更多的信息(截图,关键代码等)

zfchengjun commented 7 years ago

请问区域图中,我想将每个数据拐点那里的菱形,换成圆形,有字段选项设置吗

JohnnyZhao commented 7 years ago

X 轴目前还不支持指定 fontsize 和是否倾斜显示是吧?

tonyiweb commented 7 years ago

ring chart中颜色怎么设置呢

series: [{ name: "已完成", color:"#ffba00", data: 2, }, { name:"未完成", data: item.totalSignInTimes - 2, }],

tonyiweb commented 7 years ago

ring chart怎么使得圆环的起点是正上方,而不是右边呢 extra:{ pie:{ offsetAngle:-90 } },

txw8 commented 7 years ago

这个和swiper组件一起使用的时候, 绘画出的canvas图像 不随屏幕滑动一起移动,就感觉像是被固定定位了, 请问你们有遇到这个问题吗? (在微信开发者工具里 是正常的 但是手机上就会出现这个问题, 安卓,IOS 都有这个问题.)

tonyiweb commented 7 years ago

image 加入了等分的白色分割线 配置:
drawWhiteLine:true, whiteLineCount:10 链接:https://github.com/MobileGo2015/wx-charts

完整代码: var drawProgress =function(that){ for(var index=0;index<that.data.list.length;index++){ var item = that.data.list[index]; var signInTimes = item.hasSignInTimes; var unSignInTimes = item.totalSignInTimes - item.hasSignInTimes; var signInColor = "#ffba00"; var unSignInColor ="#f4f4f4"; if (unSignInTimes < 0){ signInColor ="#ff7e00"; unSignInColor ="#ffba00"; } new wxCharts({ canvasId: "wxChartCanvas"+item.timeStamp+""+item.activityId, type: 'ring', series: [{ name: "已完成", data: signInTimes, color: signInColor }, { name:"未完成", data: unSignInTimes, color: unSignInColor }], extra:{ pie:{ offsetAngle:-90 }, ringWidth:12 }, title: { name: (100 * signInTimes / item.totalSignInTimes).toFixed(1)+'%', color:'#999999', fontSize:15 }, width: 136, height: 136, dataLabel: false, legend:false, disablePieStroke:true, drawWhiteLine:true, whiteLineCount:10 }); }; }

liuyon7 commented 7 years ago

这个和swiper组件一起使用的时候, 绘画出的canvas图像 不随屏幕滑动一起移动,就感觉像是被固定定位了, 请问你们有遇到这个问题吗? (在微信开发者工具里 是正常的 但是手机上就会出现这个问题, 安卓,IOS 都有这个问题.),,我也遇到这个问题

boreyic commented 7 years ago

@liuyon7 我也遇到跟你一样的问题了,兄弟解决了吗?

xiaolin3303 commented 7 years ago

@liuyon7 参考#141

xiaolin3303 commented 7 years ago

@boreyic 参考 #141

cnvp commented 7 years ago

line类型中,请问怎么样不显示x轴的数据, 然后怎么改变数据点的的形状,请大神解答!!!

yang-xd commented 7 years ago

x轴 字体怎么能水平显示, 现在是倾斜显示的

liuyon7 commented 7 years ago

@boreyic 我改用定时器,自己刷新数据了

xiaolin3303 commented 7 years ago

@yang-xd x轴文案如果会发生碰撞就会自动倾斜显示

1294694985 commented 7 years ago

在Y轴设置最大最小值,不管用,数据中也没有超过y轴最大值的数据。例如,y轴上要显示1-12月份 image为什么这个hans函数返回的值不是很正确?如何正确的设置?

xiaolin3303 commented 7 years ago

@1294694985 y轴目前固定是5个刻度,min, max只是制定Y轴的数据范围

TimelyRainX commented 7 years ago

怎么实现多柱状图的情况 每个柱的颜色怎么调呢

TimelyRainX commented 7 years ago

分割线的颜色怎么调呢

Ronan-man commented 7 years ago

在柱状图中,能不能把每个柱根据数据大小设置不同颜色?

lwoshishenya commented 6 years ago

雷达图默认是三圈,怎么设置圈数呀,项目要求有5圈

xiaoyaniu commented 6 years ago

@lwoshishenya 在wxcharts.js中config中有一个参数radarGridCount:3,改成5就可以

lbt1120 commented 6 years ago

请问如何让刻度文字居中

kevintanhappy commented 6 years ago

饼图下方的类别图例太多,右边文字超出屏幕,看不到了。这个有什么参数可以设置吗?

huangjihua commented 6 years ago

请问纵坐标的刻度 可否加一个自定义刻度

yi-jy commented 6 years ago

话说,这个文档是不是没写全啊?总感觉demo图表里的参数,不止上面文档里描述的。

houwh001 commented 6 years ago

项目有很多数据,想请问下怎么实现柱状图横向排列呢?

nxy315 commented 6 years ago

请问ring的坐标怎么改啊

DaDongCode commented 6 years ago

请问怎么让文字变斜显示,或则竖直显示?谢谢

houwh001 commented 6 years ago

@DaDongCode 字体倾斜可以使用样式font-style:italic或者是font-style:oblique设置。竖直显示可以将标签宽度设置小些

DaDongCode commented 6 years ago

@houwh001 是在canvas上面画出来的文字,就像这个插件的Line和Scrollline的横轴文字那样变斜,使用ctx.fillText()

DaDongCode commented 6 years ago

您好,请问一下Scrollline中的统计图可以滑动的方法是什么? @xiaolin3303

ericwhj commented 6 years ago

没找到tonyiweb 的扩展版本。急用将就先搞了一个。 image 文件发不上来,源代码: //eric:2018-1-1 扩展Pie图支持drawWhiteLine 画10个间隔白灰等块 function getPieDataPoints(series, process, opts) { var process = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;

var count = 0;
var _start_ = opts.drawWhiteLine == true ? 2 * 0.1 * 0.10 * Math.PI : 0;
series.forEach(function (item) {
    item.data = item.data === null ? 0 : item.data;
    count += item.data;
});
series.forEach(function (item) {
    item.data = item.data === null ? 0 : item.data;
    item._proportion_ = item.data / count * process;
});
series.forEach(function (item) {
    item._start_ = _start_;
    _start_ += 2 * item._proportion_ * Math.PI;
});

return series;

} //eric:2018-1-1 扩展drawWhiteLine属性,画出渐格圈------------- var xx1=[]; var xx2 = []; if (opts.drawWhiteLine==true) { series.pop(); //默认移除最后一个serie,最后一个为未完成item var start = -90 - 2 0.1 0.15 Math.PI; for (var i = 0, len = 10; i < len; i++) { var yy = {}; yy.color = "#dbdbdb"; yy.start = start; yy.proportion = 0.10.85; start += 2 yy.proportion Math.PI; series.unshift(yy);

      var zz = {};
      zz.color = "white";
      zz._start_ =  _start_;
      zz._proportion_ = 0.1*0.15;
      _start_ += 2 * zz._proportion_ * Math.PI;
      series.push(zz);
    }

}
//-------------
series.forEach(function (eachSeries) {
    context.beginPath();
    context.setLineWidth(2);
    context.setStrokeStyle('#ffffff');
    context.setFillStyle(eachSeries.color);

提供个思路参考。。。

zengguoying commented 6 years ago

请问areaChart中如何加竖线,绘制成网格形状?在线等!

suifan commented 6 years ago

opts.legend 设置为true 不管用。

suifan commented 6 years ago

legend 点击事件 是哪个?

oo10 commented 6 years ago

canvas 宽高没问题 但是里面的圆环非常小是为什么?不应该适应canvas大小吗?