- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我用 Morris.js 画了一张图表。
我正确地填充了我的数据,我的图表也很漂亮。
看这张图:
这是我用来画图的配置:
var config = {
data: data,
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Individual Score', 'Team Score'],
fillOpacity: 0.6,
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
pointFillColors: ['#ffffff'],
pointStrokeColors: ['black'],
lineColors: ['gray', 'blue']
};
我的问题是:如何让 Y 轴渐变以仅显示 3 个值:1、2 和 3?
最佳答案
在最新的官方 Morris.js v0.5.1 中实际上没有参数可以做到这一点。
但是您可以使用 yLabelFormat
隐藏非整数的 y 值:
Morris.Area({
element: 'chart',
data: [
{ y: '2015-01', a: 1, b: 2 },
{ y: '2015-02', a: 2, b: 3 },
{ y: '2015-03', a: 2, b: 2 },
{ y: '2015-04', a: 1, b: 1 },
{ y: '2015-05', a: 2, b: 2 },
{ y: '2015-06', a: 3, b: 3 },
{ y: '2015-07', a: 1, b: 2 }
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Individual Score', 'Team Score'],
fillOpacity: 0.6,
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
pointFillColors: ['#ffffff'],
pointStrokeColors: ['black'],
lineColors: ['gray', 'blue'],
yLabelFormat: function(y){ return y != Math.round(y)?'':y; }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css" rel="stylesheet"/>
<div id="chart"></div>
或者您可以使用添加了 gridIntegers
参数的 Morris.js 的修改版本。看到这个问题:Integers as y-axis in a morris.js line chart .
必须在修改后的 Morris Area 配置中设置这些参数:
gridIntegers: true
ymin: 0 // ymin and/or ymax (a value of your choice)
或者你可以使用最新的官方 Morris.js v.0.5.1 并对其进行扩展以添加 gridIntegers
参数:
(function () {
var $, MyMorris;
MyMorris = window.MyMorris = {};
$ = jQuery;
MyMorris = Object.create(Morris);
MyMorris.Grid.prototype.gridDefaults["gridIntegers"] = false;
MyMorris.Grid.prototype.setData = function (data, redraw) {
var e, idx, index, maxGoal, minGoal, ret, row, step, total, y, ykey, ymax, ymin, yval, _ref;
if (redraw == null) {
redraw = true;
}
this.options.data = data;
if ((data == null) || data.length === 0) {
this.data = [];
this.raphael.clear();
if (this.hover != null) {
this.hover.hide();
}
return;
}
ymax = this.cumulative ? 0 : null;
ymin = this.cumulative ? 0 : null;
if (this.options.goals.length > 0) {
minGoal = Math.min.apply(Math, this.options.goals);
maxGoal = Math.max.apply(Math, this.options.goals);
ymin = ymin != null ? Math.min(ymin, minGoal) : minGoal;
ymax = ymax != null ? Math.max(ymax, maxGoal) : maxGoal;
}
this.data = (function () {
var _i, _len, _results;
_results = [];
for (index = _i = 0, _len = data.length; _i < _len; index = ++_i) {
row = data[index];
ret = {
src: row
};
ret.label = row[this.options.xkey];
if (this.options.parseTime) {
ret.x = Morris.parseDate(ret.label);
if (this.options.dateFormat) {
ret.label = this.options.dateFormat(ret.x);
} else if (typeof ret.label === 'number') {
ret.label = new Date(ret.label).toString();
}
} else {
ret.x = index;
if (this.options.xLabelFormat) {
ret.label = this.options.xLabelFormat(ret);
}
}
total = 0;
ret.y = (function () {
var _j, _len1, _ref, _results1;
_ref = this.options.ykeys;
_results1 = [];
for (idx = _j = 0, _len1 = _ref.length; _j < _len1; idx = ++_j) {
ykey = _ref[idx];
yval = row[ykey];
if (typeof yval === 'string') {
yval = parseFloat(yval);
}
if ((yval != null) && typeof yval !== 'number') {
yval = null;
}
if (yval != null) {
if (this.cumulative) {
total += yval;
} else {
if (ymax != null) {
ymax = Math.max(yval, ymax);
ymin = Math.min(yval, ymin);
} else {
ymax = ymin = yval;
}
}
}
if (this.cumulative && (total != null)) {
ymax = Math.max(total, ymax);
ymin = Math.min(total, ymin);
}
_results1.push(yval);
}
return _results1;
}).call(this);
_results.push(ret);
}
return _results;
}).call(this);
if (this.options.parseTime) {
this.data = this.data.sort(function (a, b) {
return (a.x > b.x) - (b.x > a.x);
});
}
this.xmin = this.data[0].x;
this.xmax = this.data[this.data.length - 1].x;
this.events = [];
if (this.options.events.length > 0) {
if (this.options.parseTime) {
this.events = (function () {
var _i, _len, _ref, _results;
_ref = this.options.events;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
e = _ref[_i];
_results.push(Morris.parseDate(e));
}
return _results;
}).call(this);
} else {
this.events = this.options.events;
}
this.xmax = Math.max(this.xmax, Math.max.apply(Math, this.events));
this.xmin = Math.min(this.xmin, Math.min.apply(Math, this.events));
}
if (this.xmin === this.xmax) {
this.xmin -= 1;
this.xmax += 1;
}
this.ymin = this.yboundary('min', ymin);
this.ymax = this.yboundary('max', ymax);
if (this.ymin === this.ymax) {
if (ymin) {
this.ymin -= 1;
}
this.ymax += 1;
}
if (((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'y') || this.options.grid === true) {
if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) {
this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines);
this.ymin = Math.min(this.ymin, this.grid[0]);
this.ymax = Math.max(this.ymax, this.grid[this.grid.length - 1]);
} else {
step = (this.ymax - this.ymin) / (this.options.numLines - 1);
if (this.options.gridIntegers) {
step = Math.max(1, Math.round(step));
}
this.grid = (function () {
var _i, _ref1, _ref2, _results;
_results = [];
for (y = _i = _ref1 = this.ymin, _ref2 = this.ymax; step > 0 ? _i <= _ref2 : _i >= _ref2; y = _i += step) {
_results.push(y);
}
return _results;
}).call(this);
}
}
this.dirty = true;
if (redraw) {
return this.redraw();
}
};
}).call(this);
Morris.Area({
element: 'chart',
data: [
{ y: '2015-01', a: 1, b: 2 },
{ y: '2015-02', a: 2, b: 3 },
{ y: '2015-03', a: 2, b: 2 },
{ y: '2015-04', a: 1, b: 1 },
{ y: '2015-05', a: 2, b: 2 },
{ y: '2015-06', a: 3, b: 3 },
{ y: '2015-07', a: 1, b: 2 }
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Individual Score', 'Team Score'],
fillOpacity: 0.6,
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
pointFillColors: ['#ffffff'],
pointStrokeColors: ['black'],
lineColors: ['gray', 'blue'],
gridIntegers: true,
ymin: 0
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css" rel="stylesheet" />
<div id="chart"></div>
关于javascript - 使用 Morris.js 毕业 YAxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34340857/
是否可以动态更新莫里斯图?我知道setData()将更新数据,但我想更新设置。即,用户能够选择是否堆叠条形图。 我已经尝试过: bChart.stacked = true; bChart.setDat
这个 morrisjs javascript 有什么问题? http://jsbin.com/dituriheje/edit?html,js,output ) Morris.js L
我正在尝试创建类似Google Analytics(分析)“受众群体概览”图的图形。我正在尝试将X轴上从凌晨12:00 am到11:00 pm的小时数设置为 这是我目前正在使用的: Morris.Li
我已经阅读了文档及其要求,但我不想要它 :D 尝试将其设置为未定义并删除它,但随后 javascript 提示它丢失了。 有没有办法隐藏它? 最佳答案 您可以通过下一个选项禁用它: Morris.Li
我想知道是否可以在条形图上设置最大轴值(例如,我希望数据的最高点是 y 轴的顶端)?我看到折线图上有 ymin 和 ymax 选项,但我似乎找不到有关条形图的任何信息。 此外,如果有人知道如何将轴车道
我正在使用 Morris.js 条形图。出于某种原因,应该在 HOVER OVER 上出现的数字列在左下角。有没有人为什么? 最佳答案 没有任何代码很难给出好的答案。但是,它可能与您的 CSS 文件有
是否可以以相反的顺序(0-100)设置 y 轴值? 顶部的最大值必须从 0 到底部的 100。 Morris.Line({ element: 'line-example', dat
我正在尝试根据本地数据文件 - sales.php(json 格式)动态绘制莫里斯线: [ { year: '2008', value: 20 }, { year: '2009', value
我使用 morris.js绘制折线图图形,但我无法弄清楚如何仅更改折线图中的点颜色和样式。有谁知道如何只更改点样式? 谢谢。 最佳答案 使用 pointFillColors 属性。来自文档: poin
这是当我们使用Knuth-Morris-Pratt算法时,在Scheme中计算失效函数(我们要返回多少步)的代码: (define (compute-failure-function p) (
我有一个问题,因为我做了后端的动态响应。我生成的代码是: new Morris.Line({ // ID of the element in which to draw
我在使用 Morris.js 库创建图表时遇到一些麻烦。我创建了运动应用程序,每次训练都有一些值(value)。其中之一是“锻炼”,它表示锻炼类型(“运行”、“游泳”、“骑自行车”)。我想显示带有日期
为什么我会遇到异常 Uncaught Error: Graph container element not found 当使用morris.js时? 最佳答案 解决方案:将 javascript 放在
我在 yii2 中使用了 morris js 图表,当数据范围太高时出现问题,较低的数据范围会崩溃,有什么办法可以清楚地看到它?另外,要显示整周的数据,需要在 x 轴上向上滚动。 function c
我试图暗示 morris.js 但我收到以下错误: 我试着实现了一些教程,这真的很容易,但到目前为止我得到了以下内容 new Morris.Line({ element: 'myfirstchar
我正在使用 morris.js 和 javascript 创建折线图。这是我的代码: Morris.Area({ element: 'hero-area', data: [
我希望自定义堆叠条形图上的悬停图例,这样它就不会显示在特定条形图中没有值但会显示在其他条形图中的标签。希望下面链接中的图片有助于解决问题。图片中的行军标签只有几个标签的值,但显示了所有标签。我知道我必
我有以下 .js.coffee 文件 jQuery -> Morris.Line element: 'averages_chart' data: [{month: '2014 01 01',
是否可以使用 morris.js 添加水平条形图? http://jsbin.com/uzosiq/2/embed?javascript,live 非常感谢! 最佳答案 如果你使用来自 https:/
我很好奇 morris.js 是否支持在单个标签上放置多个堆叠条以及是否有人知道解决方法。 我想要将 2 个图表堆叠在同一行上。蓝色和红色应该相互重叠,绿色和黄色应该相互重叠。 Morris.Bar(
我是一名优秀的程序员,十分优秀!