我正在使用d3 v4渲染SVG图形.我在几个元素上使用了clipPath<path>.我在rect元素上有平移行为,而clipPath正在帮助隐藏一些路径元素.在android中平移时.clipPath可以根据需要运行,但是在iOS中进行平移时,绘图会变得很时髦.见下文:
之前
我用以下代码实现了SVG剪辑:
this.line = d3.line()
.curve(d3.curveMonotoneX)
.x((d) => this.xScale(this.getDate(d)))
.y((d) => this.yScale(d.kWh));
this.area = d3.area()
.curve(d3.curveMonotoneX)
.x((d) => {
return this.xScale(this.getDate(d))
})
.y0(this.height)
.y1((d) => this.yScale(d.kWh));
// Definition for clipPath
this.svg.append("defs").append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", this.width)
.attr('transform', 'translate(0,-20)')
.attr("height", this.height + 20);
// clipPath added to area
var areaPath = this.focus.append("path")
.datum(this.data)
.attr("class", "area")
.attr('height', this.height)
.attr('fill-opacity', .2)
.attr('clip-path', 'url(#clip)')
.attr("d", this.area)
.attr("transform", "translate(0," + 80 + ")")
.style("fill", "url(#gradient)");
// clipPath …Run Code Online (Sandbox Code Playgroud) 我正在计算当前文档中有价值的输入数量.它工作正常,除了我动态添加更多输入.我无法达到价值观.
例如我可能有
<input id="participant-1"/>
<input id="participant-2"/>
...
Run Code Online (Sandbox Code Playgroud)
按钮点击后动态创建
<input id="participant-15" />
Run Code Online (Sandbox Code Playgroud)
我会在for循环中得到每个值的值
for(var i =1 ; i <25; i++)
{
...$('input#participant-' + i).val();
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行for循环来检查每个输入的值时,它只获取未动态创建的输入值.我在这里看了其他问题,但我仍然看不出如何应用类似于.on()我想要完成的事情.
新的关注问题 好了,现在我认为这是我需要更多关于如何使用.on的澄清.
我在这里有一个jsfiddle:JsFiddle示例
我在哪里创建新元素和所有文本框的模糊我想计算有多少元素有价值并记录它.现在,它将使用静态元素对blur事件做出响应.它不适用于动态创建的元素
我使用的是*ngFor填充options的<select></select>.我的问题是我可以拥有10006个中的1个的数组值<select>.表现很痛苦.我知道这是因为changeDetection或One-way Binding.有没有更好地实施的方式*ngFor进行<option>.我实际上并不需要change detection或one-way binding.
我的守则
<select [formControl]="requestForm.controls['SellCommodityId']">
<option [value]="" disabled selected>COMMODITY/GRADE</option>
<option [value]="item.Id" *ngFor="let item of fieldOptions?.Product;">{{item.Value}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
更新12-20-2016
我将select放入其中的一个Component,如下所示:
import { Component, ChangeDetectionStrategy,Input } from '@angular/core';
/**
* <ihda-select [list]="list" [control]="control" [titleOption]="title"></ihda-select>
*/
@Component({
selector:'ihda-select',
changeDetection:ChangeDetectionStrategy.OnPush,
template:`
<select [formControl]="control" class="form-control">
<option [value]="" disabled selected>{{titleOption}}</option>
<option [value]="item.Id" *ngFor="let item of list">{{item.Value}}</option>
</select>
`,
styleUrls: ['../app.component.css']
})
export class …Run Code Online (Sandbox Code Playgroud) 我在这里阅读了这个答案,MySQL - Rows to Columns,并且我已经能够将其应用于我的情况,直到聚合函数(步骤3)。
我正在尝试将下表itemname中的行转换为列:itemvalue
| 主机ID | 项目名 | 项目值 |
|---|---|---|
| 1 | 地址 | 12街 |
| 2 | 电子邮件 | 所以@gmail |
| 3 | 姓名 | 传奇 |
我应用了以下代码:
create view table_extended as (
select
history.*,
case when itemname = "address" then itemvalue end as address,
case when itemname = "email" then itemvalue end as email,
case when itemname = "name" then itemvalue end as name
from history
);
Run Code Online (Sandbox Code Playgroud)
现在我有了table_extended:
| 主机ID | 项目名 | 项目值 | 地址 | 电子邮件 | 姓名 |
|---|---|---|---|---|---|
| 1 | 地址 | 12街 | 12街 … |
我正在使用svg元素创建图表.我正在向他们应用事件处理程序.事件按预期工作,但我有一个问题,因为有时其中一个元素直接在另一个元素之上,所以当底部元素的事件应该被触发时,它不会.如果你看下面的图片,我有rect一个zoom事件.变焦event会在mouse-wheel发生时触发rect,但当圆圈覆盖它时,不会触发事件.我必须拥有它circles,rect以便在需要时可以点击它们.我怎么可能解决这个问题.我尝试在这里搜索解决方案SO,但找不到任何特定于此问题的内容.
我有一个显示圈子的JSFiddle.如果您在圆圈之外的任何位置进行缩放,则会触发缩放行为,但如果您尝试在圆圈顶部进行缩放,则缩放行为将不起作用.
我有一个d3&Ionic项目,可以在github上找到。我没有创建Plunkr,因为该错误必须通过android模拟器或android设备重现。
我有一个平移和缩放的图形。我试图一次在图表中保留约60个数据点。当用户到达“边缘”时,表示域和数据点之间的距离约为2,那么我将刷新数据,并基于新域删除和添加数据。在异步调用之前,似乎缩放变得混乱,并且平移导致缩放就像我在捏一样。平移时重绘图形时会发生这种情况。我不知道为什么。
我正在使用Ionic和d3:这是我的缩放代码的外观
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Content, LoadingController, NavController, PopoverController } from 'ionic-angular';
import { UsageLayer } from './usage-layer';
import { Observable } from 'rxjs/Rx';
import { UsageService } from './usage.service';
import * as Utils from './utils';
import * as d3 from 'd3';
import * as moment from 'moment';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,private el: ElementRef,private usageService: UsageService) {}
//public properties …Run Code Online (Sandbox Code Playgroud) 目前我正在使用Ionic 2.0.0-beta.37.其中使用的是typescript 1.8.x. 我正在尝试使用打字稿的D3版本4,但d3-v4-definitelytyped的类型使用Typescript 2.x. 我在打字时遇到编译错误,在d3-v4-definitelytyped repo上发出问题后,我了解到我需要在Ionic 2项目中使用TS 2.x.
这是我得到的错误:
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(150,30): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(167,24): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(173,55): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(191,24): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-brush/index.d.ts(30,37): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(38,56): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(39,25): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(41,59): Error TS1110: Type expected.
Run Code Online (Sandbox Code Playgroud)
我查看package.json了我的主IONIC目录中的文件,我没有看到typescript作为依赖项,所以我认为它正在使用其他东西来定义版本.我知道了:
所以我进去 …
我有一个图表,d3.radialLine可以在这个fiddle 中看到。通过在适当的轴值上绘制圆圈来可视化我线上的数据点。我需要在 svg 元素的中间有一条线,它可以让我读取接触它的绘制数据点。您可以看到我正在尝试完成的图形图像:
我想以编程方式旋转,例如顺时针旋转,以便十二月与红线对齐,并且能够读取该数据点。我知道我必须获得x2红线的值并使用 12 月值的“x2”来找出我需要旋转图形的度数,但我似乎无法弄清楚那部分。代码取自Radar Chart。
我知道旋转的公式..d3.select(...).attr('transform', 'rotate(degree, x, y)'
代码
//////////////////////////////////////////////////////////////
//////////////////////// Set-Up //////////////////////////////
//////////////////////////////////////////////////////////////
var margin = {top: 100, right: 100, bottom: 100, left: 100},
width = Math.min(700, window.innerWidth - 10) - margin.left - margin.right,
height = Math.min(width, window.innerHeight - margin.top - margin.bottom - 20);
//////////////////////////////////////////////////////////////
////////////////////////// Data //////////////////////////////
//////////////////////////////////////////////////////////////
var data = [
// Yearly
[{axis:"Jan",value: 700},
{axis:"Feb",value: 1453},
{axis:"March",value: 1300},
{axis:"April",value: 1534},
{axis:"May",value: 1534},
{axis:"June",value: …Run Code Online (Sandbox Code Playgroud) 我正在使用d3.js v4.我目前正在实施程序化缩放.这种平移和缩放教程有很大帮助.我的缩放适用于滚轮,但我想创建缩放按钮.我知道缩放和平移的必要条件是翻译[tx, ty]和比例因子k.我正在为x-Axis使用时间刻度.我已经成功地获得tx和比例因子k,通过获取的像素值p1 (point 1),并p2(point 2)在x轴,然后使用这些值来获得AK(比例系数).像这样:
var k = 500 / (xScale(p2) - xScale(p1)); //500 is desired pixel diff. between p1 and p2, and xScale is my d3.scaleTime() accessor function.
// for this zoom i just want the first value and last value to be at scale difference of the entire width.
Run Code Online (Sandbox Code Playgroud)
然后我用这个计算tx:
var tx = 0 - k * p1;
Run Code Online (Sandbox Code Playgroud)
然后将它喂入d3.zoomIdentity()并重新调整我的xdomain.我创建了一个缩小按钮的按钮.问题是当我放大然后尝试使用按钮缩小时,它会缩小,但缩小x轴.我似乎无法找到为什么它缩小x轴而不是正确缩小. …
我有一个在Canvas中实现的d3图。图形性能在Chrome中很棒,但是当我使用Ionic(webview)部署它时,缩放和平移重绘在android上确实非常惊人,而在iOS上甚至更慢。
我最初是使用SVG开发该图的,但是在确信画布可以更平滑地运行之后切换到了画布。
的HTML
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<canvas width="300" height="300"></canvas>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
画布初始化
mode = 'monthly';
canvas = document.querySelector("canvas");
context = canvas.getContext("2d");
margin = { top: 20, right: 20, bottom: 30, left: 50 },
width = canvas.width - margin.left - margin.right,
height = canvas.height - margin.top - margin.bottom;
var parseTime = d3.timeParse("%d-%b-%y");
// setup scales
x = d3.scaleTime()
.range([0, width]);
x2 = d3.scaleTime().range([0, width]);
y = d3.scaleLinear()
.range([height, 0]);
// setup domain
x.domain(d3.extent(data, function …Run Code Online (Sandbox Code Playgroud)