Javascript D3中轴和网格的不同颜色
我想为轴(x和y)和图形网格不同的颜色。我试着改变CSS,但没有成功 我已经附上了图形代码和css与此。css代码如下所示Javascript D3中轴和网格的不同颜色,javascript,css,d3.js,Javascript,Css,D3.js,我想为轴(x和y)和图形网格不同的颜色。我试着改变CSS,但没有成功 我已经附上了图形代码和css与此。css代码如下所示 .axis path, .axis line { fill: none; /*stroke: #000;*/ stroke: #B2B2B2; shape-rendering: crispEdges; opacity: 0.5; } .area_characteristics_temperature { fill: ste
.axis path,
.axis line {
fill: none;
/*stroke: #000;*/
stroke: #B2B2B2;
shape-rendering: crispEdges;
opacity: 0.5;
}
.area_characteristics_temperature {
fill: steelblue;
opacity:0.5;
border: 0px;
margin:0px;
overflow: hidden;
}
.area_characteristics_temperature_3yr {
fill: #7da7ca;
opacity:0.5;
border: 0px;
margin:0px;
overflow: hidden;
}
.area_characteristics_temperature_10yr {
fill: #676767;
opacity:0.5;
border: 0px;
margin:0px;
overflow: hidden;
}
.area_characteristics_temperature_prev {
fill: #eec7ea;
opacity:0.5;
border: 0px;
margin:0px;
overflow: hidden;
}
.line {
fill: transparent;
stroke:red;
stroke-width:3px;
}
.line1 {
fill: transparent;
stroke:green;
stroke-width:3px;
}
.line_characteristics_current_temperature_max{
fill: transparent;
/*stroke:red;*/
stroke:#CC3300;
stroke-width:3px;
}
.line_characteristics_current_temperature_min{
fill: transparent;
/*stroke:yellow;*/
stroke:#0099CC;
stroke-width:3px;
}
.line_characteristics_forecast_temperature_max{
fill: transparent;
/*stroke:green;*/
stroke:#CC3300;
stroke-width:3px;
stroke-height:3px;
/*stroke-dasharray:2.5px,6px;*/
stroke-dasharray:2.5px,5.5px,2.5px,5.5px;
stroke-soft:5px;
stroke-linecap:round;
stroke-height:3px;
stroke-width:3.4px;
}
.line_characteristics_forecast_temperature_min{
fill: transparent;
stroke:#0088C3;
stroke-width:3px;
stroke-height:3px;
/*stroke-dasharray:3px,6px,3px,6px;*/
stroke-dasharray:2.5px,5.5px,2.5px,5.5px;
stroke-soft:5px;
stroke-linecap:round;
stroke-height:3px;
stroke-width:3.4px;
strokeDashoffset:10px,5px;
}
#wgtmsr option{
width:150px;
}
/*<DEMO>*/
#nav {
height:200px;
width:100px;
float:left;
padding:5px;
padding-bottom:50px;
}
#section {
width:350px;
float:left;
padding:10px;
}
/* Main style*/
.widget_sidebar{
min-width: 200px;
max-width:25%;
overflow:hidden;
float:left
}
.widget_graphArea{
min-width: 200px;
max-width:75%;
overflow:hidden;
}
。轴路径,
.轴线{
填充:无;
/*行程:#000*/
冲程:#B2B2B2;
形状渲染:边缘清晰;
不透明度:0.5;
}
.面积特性温度{
填充:钢蓝;
不透明度:0.5;
边界:0px;
边际:0px;
溢出:隐藏;
}
.面积特征温度3年{
填充:#7da7ca;
不透明度:0.5;
边界:0px;
边际:0px;
溢出:隐藏;
}
.面积特征温度10年{
填充:#6767;
不透明度:0.5;
边界:0px;
边际:0px;
溢出:隐藏;
}
.区域特征温度前{
填充:#eec7ea;
不透明度:0.5;
边界:0px;
边际:0px;
溢出:隐藏;
}
.线路{
填充:透明;
笔画:红色;
笔画宽度:3px;
}
.line1{
填充:透明;
笔画:绿色;
笔画宽度:3px;
}
.线路\u特性\u电流\u温度\u最大值{
填充:透明;
/*笔画:红色*/
行程:#CC3300;
笔画宽度:3px;
}
.线路特性\u电流\u温度\u最小值{
填充:透明;
/*笔画:黄色*/
冲程:#0099CC;
笔画宽度:3px;
}
.线路特性预测温度最大值{
填充:透明;
/*笔画:绿色*/
行程:#CC3300;
笔画宽度:3px;
冲程高度:3倍;
/*行程:2.5px,6px*/
行程数组:2.5px,5.5px,2.5px,5.5px;
冲程软:5px;
笔划线头:圆形;
冲程高度:3倍;
笔画宽度:3.4px;
}
.线路特性预测温度最小值{
填充:透明;
行程:#0088C3;
笔画宽度:3px;
冲程高度:3倍;
/*行程数组:3px,6px,3px,6px*/
行程数组:2.5px,5.5px,2.5px,5.5px;
冲程软:5px;
笔划线头:圆形;
冲程高度:3倍;
笔画宽度:3.4px;
行程偏移:10px,5px;
}
#WGTMR选项{
宽度:150px;
}
/**/
#导航{
高度:200px;
宽度:100px;
浮动:左;
填充物:5px;
填充底部:50px;
}
#部分{
宽度:350px;
浮动:左;
填充:10px;
}
/*主要风格*/
.widget_侧边栏{
最小宽度:200px;
最大宽度:25%;
溢出:隐藏;
浮动:左
}
图哈雷亚酒店{
最小宽度:200px;
最大宽度:75%;
溢出:隐藏;
}
图形代码:我使用D3进行图形编码
var self = this;
this.divID = divID;
this.forecastEnabled = true;
this.currentEnabled = true;
this.averagesEnabled = true;
this.currentData = [];
this.areaClass = "area_characteristics_temperature";
this.averagesData = []
this.forecastdata = new Array();
this.merged_data = new Array();
this.svg = null;
this._currentDataTrail = {temperature_max: 0, temperature_min: 0, date: 0}
this.parseDate = d3.time.format("%Y-%m-%d").parse;
w = $("#" + this.divID).width();
h = $("#" + this.divID).height();
this.boxing = {top: 20, right: 30, bottom: 30, left: 50},
this.width = w - this.boxing.left - this.boxing.right,
this.height = h - this.boxing.top - this.boxing.bottom;
this.x = d3.time.scale()
.range([0, this.width]);
this.y = d3.scale.linear()
.range([this.height, 0]);
this.xAxis = d3.svg.axis()
.scale(this.x)
// .ticks(d3.time.day, 1)
// .tickFormat(d3.time.format('%b %d'))
.orient("bottom");
this.yAxis = d3.svg.axis()
.scale(this.y)
.orient("left")
.ticks(5, 0)
.tickPadding(10);
this.svg = null;
this.line_characteristics = d3.svg.line()
.x(function (d) {
return self.x(d.date);
})
.y(function (d) {
return self.y(d.temperature);
});
this.line_characteristics_temperature_min = d3.svg.line()
.x(function (d) {
return self.x(d.date);
})
.y(function (d) {
return self.y(d.temperature_min);
});
this.line_characteristics_temperature_max = d3.svg.line()
.x(function (d) {
return self.x(d.date);
})
.y(function (d) {
return self.y(d.temperature_max);
});
this.area_characteristics_temperature = d3.svg.area()
.x(function (d) {
return self.x(d.date);
})
.y0(function (d) {
return self.y(d.temperature_max);
})
.y1(function (d) {
return self.y(d.temperature_min);
});
self.updateCurrentData = function (newData, append)
{
var _currentMaxDate = new Date(0);
newData.forEach(function (d) {
d.date = self.parseDate(d.date);
d.temperature_max = d.temperatures.max;
d.temperature_min = d.temperatures.min;
if (d.date > _currentMaxDate) {
_currentMaxDate = d.date;
self._currentDataTrail.temperature_max = d.temperature_max;
self._currentDataTrail.temperature_min = d.temperature_min;
self._currentDataTrail.date = d.date;
}
});
if (append) {
self.currentData = self.currentData.concat(newData);
} else {
self.currentData = newData;
}
self.forecastData = new Array();
self.updateMerged();
};
self.setAreaClass = function (css_class) {
self.areaClass = css_class;
}
self.updateForecastData = function (newData)
{
self.forecastData = new Array();
newData.forEach(function (d) {
d.date = self.parseDate(d.date);
d.temperature_max = d.forecast[0].temperatures.max;
d.temperature_min = d.forecast[0].temperatures.min;
});
if (self._currentDataTrail && self._currentDataTrail.date) {
self.forecastData.push(self._currentDataTrail)
}
self.forecastData = self.forecastData.concat(newData)
self.updateMerged();
};
self.updateAveragesData = function (newData, append)
{
var _temp = new Date();
var current = new Date(_temp.getFullYear(), 0, 1);
newData.forEach(function (d) {
if (d.minTemp) {
current.setDate(current.getDate() + 1);
d.temperature_max = d.maxTemp.average.toFixed(4);
d.temperature_min = d.minTemp.average.toFixed(4);
var date = current.getFullYear() + "-" + d.day;
d.date = self.parseDate(date);
} else {
d.date = self.parseDate(d.date);
d.date.setFullYear(d.date.getFullYear() + 1)
d.temperature_max = d.temperatures.max;
d.temperature_min = d.temperatures.min;
}
});
if (append) {
self.averagesData = self.averagesData.concat(newData);
} else {
self.averagesData = newData;
}
self.updateMerged();
};
self.updateMerged = function ()
{
self.merged_data = new Array();
if (self.currentData != undefined && self.currentData instanceof Array && self.currentData.length > 0 && self.forecastData != undefined && self.forecastData instanceof Array && self.forecastData.length > 0) {
self.merged_data = self.merged_data.concat(self.currentData)
self.merged_data = self.merged_data.concat(self.forecastData)
} else if (self.currentData != undefined && self.currentData instanceof Array && self.currentData.length > 0) {
self.merged_data = self.merged_data.concat(self.currentData);
} else if (self.forecastData != undefined && self.forecastData instanceof Array && self.forecastData.length > 0) {
self.merged_data = self.merged_data.concat(self.forecastData);
}
};
self.redraw = function () {
w = $("#" + self.divID).width();
h = $("#" + self.divID).height();
self.width = w - self.boxing.left - self.boxing.right,
self.height = h - self.boxing.top - self.boxing.bottom;
self.x = d3.time.scale()
.range([0, self.width]);
self.y = d3.scale.linear()
.range([self.height, 0]);
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.day, 1)
.tickFormat(d3.time.format('%b %d'))
.orient("bottom");
self.yAxis = d3.svg.axis()
.scale(self.y)
.orient("left")
.tickSize(-self.width)
.ticks(5, 0)
.tickPadding(10);
if (self.svg !== null) {
self.svg.remove();
}
$("#" + self.divID).html("");
self.svg = d3.select("#" + self.divID).append("svg")
.attr("width", self.width + self.boxing.left + self.boxing.right)
.attr("height", self.height + self.boxing.top + self.boxing.bottom)
.append("g")
.attr("transform", "translate(" + self.boxing.left + "," + self.boxing.top + ")");
var minDate = new Date(2999, 01, 01);
self.merged_data.forEach(function (d) {
if (d.date < minDate) {
minDate = d.date;
}
});
var maxDate = new Date(0);
self.merged_data.forEach(function (d) {
if (d.date > maxDate) {
maxDate = d.date;
}
});
var totalDateDiff = maxDate - minDate;
totalDateDiff = totalDateDiff / (1000 * 60 * 60 * 24);
if (w < 500 && !isNaN(totalDateDiff)) {
if (totalDateDiff < 30) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.days, 7)
.tickFormat(d3.time.format('%b %d'))
.orient("bottom");
} else if (totalDateDiff > 30 && totalDateDiff < 150) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.months)
.tickFormat(d3.time.format('%b %y'))
.orient("bottom");
} else if (totalDateDiff > 150 && totalDateDiff < 365) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.years)
.tickFormat(d3.time.format('%b %y'))
.orient("bottom");
} else if (totalDateDiff > 365) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.years)
.tickFormat(d3.time.format('%Y'))
.orient("bottom");
}
} else if (w > 500 && !isNaN(totalDateDiff)) {
if (totalDateDiff < 15) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.days, 1)
.tickFormat(d3.time.format('%b %d'))
.orient("bottom");
} else if (totalDateDiff > 15 && totalDateDiff <= 30) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.days, 4)
.tickFormat(d3.time.format('%b %d'))
.orient("bottom");
} else if (totalDateDiff > 30 && totalDateDiff < 100) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.months, 1)
.tickFormat(d3.time.format('%b %y'))
.orient("bottom");
} else if (totalDateDiff > 100 && totalDateDiff < 365) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.months)
.tickFormat(d3.time.format('%b %y'))
.orient("bottom");
} else if (totalDateDiff > 365) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.years)
.tickFormat(d3.time.format('%b %Y'))
.orient("bottom");
}
} else if (isNaN(w) || isNaN(totalDateDiff)) {
self.xAxis = d3.svg.axis()
.scale(self.x)
.ticks(d3.time.years)
.tickFormat(d3.time.format('%Y'))
.orient("bottom");
}
self.x.domain(d3.extent(self.merged_data, function (d) {
return d.date;
}));
self.y.domain([d3.min(self.merged_data, function (d) {
return d.temperature_min - 10;
}), d3.max(self.merged_data, function (d) {
return d.temperature_max + 10;
})]);
self.svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + self.height + ")")
.call(self.xAxis.orient("bottom"));
self.svg.append("text")
.attr("x", 0)
.attr("y", self.height)
.style("text-anchor", "middle")
.text("");
self.svg.append("g")
.attr("class", "y axis")
.call(self.yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -85)
.attr("y", 6)
.attr("dy", ".71em")
.style("text-align", "middle")
.text("Temperature(°C)");
self.svg.append("path")
.datum(self.averagesData)
.attr("class", self.areaClass)
.attr("d", self.area_characteristics_temperature);
if (self.currentEnabled === true && self.currentData instanceof Array && self.currentData.length > 0) {
self.svg.append("path")
.datum(self.currentData)
.attr("class", "line_characteristics_current_temperature_max")
.attr("d", self.line_characteristics_temperature_max);
self.svg.append("path")
.datum(self.currentData)
.attr("class", "line_characteristics_current_temperature_min")
.attr("d", self.line_characteristics_temperature_min);
}
if (self.forecastEnabled === true && self.forecastData instanceof Array && self.forecastData.length > 0) {
self.svg.append("path")
.datum(self.forecastData)
.attr("class", "line_characteristics_forecast_temperature_max")
.attr("d", self.line_characteristics_temperature_max)
.style("stroke-dasharray", "2.5,7");
self.svg.append("path")
.datum(self.forecastData)
.attr("class", "line_characteristics_forecast_temperature_min")
.attr("d", self.line_characteristics_temperature_min)
.style("stroke-dasharray", "2.5,7");
}
}
self.showCurrent = function (show)
{
self.currentEnabled = show;
};
self.showForecast = function (show)
{
self.forecastEnabled = show;
};
self.showAverages = function (show)
{
self.averagesEnabled = show;
};
}
var self=this;
this.divID=divID;
this.forecasted=true;
this.currentEnabled=true;
this.averagesEnabled=真;
this.currentData=[];
this.areaClass=“区域特性温度”;
this.averagesData=[]
this.forecastdata=新数组();
this.merged_data=新数组();
this.svg=null;
这。_currentDataTrail={temperature\u max:0,temperature\u min:0,date:0}
this.parseDate=d3.time.format(“%Y-%m-%d”).parse;
w=$(“#”+this.divID).width();
h=$(“#”+this.divID).height();
this.boxing={top:20,right:30,bottom:30,left:50},
this.width=w-this.boxing.left-this.boxing.right,
this.height=h-this.boxing.top-this.boxing.bottom;
this.x=d3.time.scale()
.范围([0,此宽度]);
this.y=d3.scale.linear()
.范围([this.height,0]);
this.xAxis=d3.svg.axis()
.scale(此.x)
//.滴答声(d3.time.day,1)
//.tickFormat(d3.time.format(“%b%d”))
.东方(“底部”);
this.yAxis=d3.svg.axis()
.scale(this.y)
.东方(“左”)
.滴答声(5,0)
.1(10);
this.svg=null;
this.line_characteristics=d3.svg.line()
.x(功能(d){
返回self.x(日期);
})
.y(功能(d){
返回自y(d.温度);
});
this.line\u characteristics\u temperature\u min=d3.svg.line()
.x(功能(d){
返回self.x(日期);
})
.y(功能(d){
返回自身y(d.温度_min);
});
this.line\u characteristics\u temperature\u max=d3.svg.line()
.x(功能(d){
返回self.x(日期);
})
.y(功能(d){
返回自身y(d.温度_最大值);
});
this.area\u characteristics\u temperature=d3.svg.area()
.x(功能(d){
返回self.x(日期);
})
.y0(功能(d){
返回自身y(d.温度_最大值);
})
.y1(功能(d){
返回自身y(d.温度_min);
});
self.updateCurrentData=函数(newData,append)
{
var _currentMaxDate=新日期(0);
newData.forEach(函数(d){
d、 日期=自解析日期(d.date);
d、 温度_max=d.temperatures.max;
d、 温度_min=d.temperatures.min;
如果(d.date>\u currentMaxDate){
_currentMaxDate=d.date;
self.\u currentDataTrail.temperature\u max=d.temperature\u max;
self.\u currentDataTrail.temperature\u min=d.temperature\u min;
self.\u currentDataTrail.date=d.date;
}
});
如果(附加){
self.currentData=self.currentData.concat(newData);
}否则{
self.currentData=新数据;
}
self.forecastData=新数组();
self.update();
};
self.setAreaClass=函数(
.axis path, .axis line{
stroke: navy;
fill: none;
}
.y.axis path{
stroke: brown;
fill: none;
}
.y.axis line{
stroke: grey;
opacity: 0.5;
}