I am currently working with a jvectormap. Each county has a data-code (example: 48201). Here is my code for the counties that I have colored so far...
jvm.Map.maps = {};
jvm.Map.defaultParams = {
map: 'us_lcc_en',series: {
regions: [{
values: {
/* --------------- Active Franchise --------------- */
'42029':'#eb2e4d',
'42091':'#eb2e4d',
'42101':'#eb2e4d',
'42045':'#eb2e4d',
'42017':'#eb2e4d',
'42077':'#eb2e4d',
'42095':'#eb2e4d',
'48085':'#eb2e4d',
'48113':'#eb2e4d',
'48439':'#eb2e4d',
'48121':'#eb2e4d',
/* --------------- Available Franchise --------------- */
'42129':'#5d9eec',
'42007':'#5d9eec',
'42125':'#5d9eec',
'42019':'#5d9eec',
'42003':'#5d9eec',
'13067':'#5d9eec',
'13121':'#5d9eec',
'13057':'#5d9eec',
'13135':'#5d9eec',
'13089':'#5d9eec',
'13063':'#5d9eec',
'13151':'#5d9eec',
'13297':'#5d9eec',
'13117':'#5d9eec',
'48339':'#5d9eec',
'48201':'#5d9eec',
'48157':'#5d9eec',
'48167':'#5d9eec',
'48039':'#5d9eec',
'48029':'#5d9eec',
'48187':'#5d9eec',
'48091':'#5d9eec',
'04013':'#5d9eec',
'09003':'#5d9eec',
'09013':'#5d9eec',
'09001':'#5d9eec',
'09009':'#5d9eec',
'09007':'#5d9eec',
'09005':'#5d9eec',
/* --------------- Pending Franchise --------------- */
'48491':'#83a85d',
'48453':'#83a85d',
'48209':'#83a85d',
},
attribute:'fill',
"stroke-width": 4
}]
},
backgroundColor: '#ffffff',
zoomButtons: true,
zoomOnScroll: false,
panOnDrag: true,
zoomMax: 8,
zoomMin: 1,
zoomStep: 1.6,
zoomAnimate: true,
regionsSelectable: false,
markersSelectable: false,
bindTouchEvents: true,
regionStyle: {
initial: {
fill: 'rgb(204, 204, 204)',
"fill-opacity": 1,
stroke: 'rgb(204, 204, 204)',
"stroke-width": 0,
"stroke-opacity": 1,
},
hover: {
"fill-opacity": 0.7,
cursor: 'pointer'
},
selected: {
fill: 'yellow'
},
selectedHover: {
}
},
regionLabelStyle: {
initial: {
'font-family': 'Verdana',
'font-size': '12',
'font-weight': 'bold',
cursor: 'default',
fill: 'black',
},
hover: {
cursor: 'pointer'
}
},
markerStyle: {
initial: {
fill: 'grey',
stroke: '#505050',
"fill-opacity": 1,
"stroke-width": 1,
"stroke-opacity": 1,
r: 5
},
hover: {
stroke: 'black',
"stroke-width": 2,
cursor: 'pointer'
},
selected: {
fill: 'blue'
},
selectedHover: {
}
},
markerLabelStyle: {
initial: {
'font-family': 'Verdana',
'font-size': '12',
'font-weight': 'bold',
cursor: 'default',
fill: 'black'
},
hover: {
cursor: 'pointer'
}
}
};
jvm.Map.apiEvents = {
onRegionTipShow: 'regionTipShow',
onRegionOver: 'regionOver',
onRegionOut: 'regionOut',
onRegionClick: 'regionClick',
onRegionSelected: 'regionSelected',
onMarkerTipShow: 'markerTipShow',
onMarkerOver: 'markerOver',
onMarkerOut: 'markerOut',
onMarkerClick: 'markerClick',
onMarkerSelected: 'markerSelected',
onViewportChange: 'viewportChange'
};
As you can see at the bottom...the attribute is set to 'fill'. I also want to add 'stroke'. How do I go about adding that second attribute?
Attributes in a javaScript object are separated by commas. Suppose you wanted to add a stroke-width attribute:
In this case, you would change the tail end, near the bottom, to look something like this:
'48491':'#83a85d',
'48453':'#83a85d',
'48209':'#83a85d',
},
attribute: 'fill',
stroke-width: 4
}]
},
Which should make you happy. Though, as an aside, stroke-width will actually be the third attribute of 'regions': you'll note that values is written in the form of "values: {...}," -- it's an attribute too!
Related
By default, Victory scatters all bars across the chart:
And the code:
<VictoryChart
width={650}
theme={VictoryTheme.material}
domainPadding={30}
>
<VictoryAxis
tickFormat={data.map(x => x.title)}
style={{
axis: { stroke: 'rgb(236, 239, 241)', strokeWidth: 1, strokeDasharray: [10, 5]},
grid: { stroke: false },
ticks: { stroke: 'none', size: 0 },
tickLabels: { fontSize: 12, padding: 15 }
}}
/>
<VictoryAxis
crossAxis={false}
domain={[0, 2000]}
dependentAxis
tickFormat={x => x}
style={{
axis: { stroke: false },
axisLabel: { fontSize: 12, padding: 50 },
ticks: { stroke: 'none', size: 0 },
tickLabels: { size: 0, padding: 20 }
}}
/>
<VictoryBar
data={dataset}
y="value"
x="title"
style={{
data: { fill: ({ datum }) => datum.color },
}}
/>
</VictoryChart>
How to center them and make middle an entry point for scattering? I'm looking for something like an alignment prop for root chart component
I use a flotcharts JS linechart to display the value of different stock tradepositions. The user can show/hide each trade on the chart via a checkbox above the chart.
By default, linecharts use default or predefined colors from me in the order the series are created. So the first line gets color1, the second color 2 etc.
This is not very good for this situation, because when the user hides the line for trade one, the previously trade two becomes the new "first line" and also changes its color from color 2 to color 1.
As the data represented by the line are still the same this behaviour is very irritating.
To solve this I would like to assign a color to a series by it's name, id or similar rather than by the order it was created on the chart, as this identifier stays the same even after adding/removing other lines from the chart.
How can I do this?
Currently I use a code like this to set the color for the first, second etc line.
var datatoprint=[];
for(var key in arrTradeSymbols){
if (arrTradeSymbols[key].visible==true){
datatoprint.push(arrTradeSymbols[key].data);
jQuery("#symb_"+arrTradeSymbols[key].tradeid).prop("checked",true);
}
}
var plot = $.plot(jQuery("#kt_flotcharts_pl"), datatoprint, {
legend: {
position: "nw",
},
series: {
lines: {
show: true,
lineWidth: 2,
fill: false,
},
points: {
show: true,
radius: 3,
lineWidth: 1,
color: '#00ff00'
},
shadowSize: 2
},
grid: {
hoverable: true,
clickable: true,
tickColor: "#eee",
borderColor: "#eee",
borderWidth: 1
},
colors: ['#0083d0', '#1dc9b7'],
xaxis: {
mode: "time",
tickSize: [5, "day"],
tickLength: 0,
tickColor: "#eee",
},
yaxis: {
ticks: 11,
tickDecimals: 0,
tickColor: "#eee",
}
});
That's easy: just supply an array of objects with the color along with the data instead of only the data as an array.
Example snippet:
var arrTradeSymbols = {
trade1: {
color: "red",
data: [
[1, 3],
[2, 4],
[3.5, 3.14]
]
},
trade2: {
color: "green",
data: [
[1, 4],
[2, 11.01],
[3.5, 5.14]
]
}
};
function run() {
var datatoprint = [];
for (var key in arrTradeSymbols) {
if ($("#" + key).is(":checked")) {
datatoprint.push(arrTradeSymbols[key]);
}
}
$.plot($("#kt_flotcharts_pl"), datatoprint, {
legend: {
position: "nw",
},
series: {
lines: {
show: true,
lineWidth: 2,
fill: false
},
points: {
show: true,
radius: 3,
lineWidth: 1
},
shadowSize: 2
},
grid: {
hoverable: true,
clickable: true,
tickColor: "#eee",
borderColor: "#eee",
borderWidth: 1
},
xaxis: {
ticks: 5
},
yaxis: {
ticks: 11,
tickDecimals: 0,
tickColor: "#eee",
}
});
}
run();
$("input").on("input", run);
#kt_flotcharts_pl {
width: 400px;
height: 200px;
border: 1px solid black;
}
label {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.min.js"></script>
<label><input type="checkbox" id="trade1" checked> Red</label>
<label><input type="checkbox" id="trade2" checked> Green</label>
<div id="kt_flotcharts_pl"></div>
html
js
var myChart = echarts.init(document.getElementById("main"));
window.onresize = myChart.resize;
var statistics = {
title: {
text: "面积",
textStyle: {
fontWeight: "normal",
color: "#fff",
fontSize: 14
},
left: "center"
},
tooltip: {
// 鼠标移动柱状图是提示文字
show: true
},
legend: {
// data: ['面积'],
textStyle: {
fontSize: 12
}
},
xAxis: {
data: ["灌木", "森林", "森林", "树木", "小树", "大树", "红树"],
axisLabel: {
show: true,
textStyle: {
color: "#fff"
}
},
axisLine: {
lineStyle: {
color: "#094060"
}
}
},
yAxis: {
axisLine: {
lineStyle: {
color: "#094060"
}
},
axisLabel: {
show: true,
textStyle: {
color: "#fff"
}
},
splitLine: {
lineStyle: {
color: ["#07405c"]
}
}
},
itemStyle: {
color: "#06ae7c",
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
},
series: [
{
type: "bar",
barWidth: 48,
data: [38, 23, 35, 12, 26, 8, 36]
}
]
};
myChart.setOption(statistics);
The echarts container in the tab switch width is set to 100%, but no matter how to set the width, are only 100px, the Internet that is because the tab bar tried to hide cause, many of the above methods, are not normal display, followed by window.onresize = myChart.resize in the code; only when changing the size of the browser window to display properly, but if you do not change the size of the window or after 100px, before we have encountered this kind of situation is how to solve?
put the class "echart" in each div chart, and execute that in your js.
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
$(".echart").each(function() {
var id = $(this).attr('echarts_instance');
window.echarts.getInstanceById(id).resize();
});
});
I have discovered one workaround for this issue. Try to call the resize event of window object when you switch tabs. To achieve it with jQuery is straightforward:
$(window).trigger('resize');
var myChart=$("#myChart");
myChart.style.width=window.innerWidth+'px';
chartObj=echarts.init(myChart);
chartObj.setOption(option);
I am new to jquery jvectormap. Currently my vectormap function look like below.
$('#locations-div').vectorMap({
map : 'world_mill_en',
normalizeFunction: 'polynomial',
backgroundColor : 'transparent',
scaleColors : ['#C8EEFF', '#0071A4'],
regionStyle : {
initial : {
fill : 'rgba(210, 214, 222, 1)',
'fill-opacity' : 1,
stroke : 'none',
'stroke-width' : 0,
'stroke-opacity': 1
},
selected : {
fill: 'yellow'
},
selectedHover: {}
},
markerStyle : {
initial: {
fill : '#328cc1',
stroke: 'none'
},
hover: {
fill: '#d98310',
cursor: 'pointer',
stroke: 'none'
}
},
series: {
markers: [{
attribute: 'r',
scale: [5, 15],
values: items_sizes
}]
},
markers : items_locations,
onMarkerLabelShow: function (event, label, code) {
var markers = $('#locations-div').vectorMap('get', 'mapObject').markers;
label.css('background-color', '#fff');
label.css('border', 'solid 1px #ddd');
label.css('padding', '0px');
label.css('font-color', 'white');//#292b2c
label.html(markers[code].config.name).css("fontSize", "15px");
},
onRegionLabelShow: function(e, el, code){
e.preventDefault();
}
});
My markers are as follows.
{latLng: [38.90, -98.45], name: 'A long text of about 100 lines of html code'}
Currently, the Marker label looks like below.
I can't scroll the content on the label. When I move the mouse into the label it disappears. How can I fix that?
First problem: When I put a hover event on a raphael path, the effect is apply on every diffrent path. So, when I pass over the path, it changes the fill of that single path, after mouseout it should stay filled with an active color. If I put a hover event on another path "last hovered path" must be filled with default color.
Second problem: When i put hover event on text - back path not fills with color.
This is my code.
var paths = {
part_1: {
name: 'part_1',
path: 'M194 139c-21,35 -33,76 -33,119 0,6 0,12 1,18l-125 10c-1,-9 -1,-18 -1,-28 0,-51 11,-99 30,-142 41,10 84,17 129,23z',
img: 'images/pol.png',
desc: "Теплые\nполы"
},
part_2: {
name: 'part_1',
path: 'M209 400l-97 78c-41,-52 -69,-116 -75,-186l125 -11c5,44 22,85 48,118z',
img: 'images/rad.png',
desc: 'Котлы\nи радиаторы'
},
part_3: {
name: 'part_1',
path: 'M116 483l97 -79c5,5 9,11 14,16 25,25 57,45 92,56l-36 120c-55,-18 -104,-48 -144,-87 -8,-8 -16,-17 -23,-26l0 0z',
img: 'images/lam.png',
desc: 'Светодиодное\n освещение'
},
part_4: {
name: 'part_1',
path: 'M454 478l36 120c-32,10 -66,15 -101,15 -35,0 -68,-5 -101,-14l36 -120c20,6 42,9 64,9 22,0 44,-3 64,-9z',
img: 'images/pol.png',
desc: 'Натяжные\nпотолки,\nаксессуары '
},
part_5: {
name: 'part_1',
path: 'M565 405l97 79c-7,9 -15,17 -23,25 -40,39 -89,70 -144,87l-36 -120c35,-11 66,-31 92,-56 5,-5 10,-10 14,-16l0 0z',
img: 'images/camera.png',
desc: 'Системы\nбезопасности'
},
part_6: {
name: 'part_1',
path: 'M666 479l-97 -80c26,-33 42,-72 47,-116l125 10c-7,70 -34,134 -75,186z',
img: 'images/vent.png',
desc: 'Вентиля-\nционные\nсистемы'
},
part_7: {
name: 'part_1',
path: 'M742 286l-125 -10c0,-6 1,-12 1,-18 0,-44 -12,-84 -33,-119 45,-6 88,-13 129,-23 19,44 30,92 30,142 0,10 0,19 -1,28z',
img: 'images/auto.png',
desc: 'Гаражные\nворота,\nрольставни'
}
}
function labelPath( pathObj, text, textattr )
{
if ( textattr == undefined )
textattr = { 'font-size': 18, fill: '#722d00', stroke: '#393738', cursor: 'pointer', 'stroke-width': 0, "text-anchor":"start", 'stroke-linejoin': 'round', 'font-family': 'Arial,Helvetica,sans-serif', 'font-weight': 'bold' };
var bbox = pathObj.getBBox();
var textObj = pathObj.paper.text( bbox.x + bbox.width / 4, bbox.y + bbox.height / 2, text ).attr( textattr );
return textObj;
}
$(function(){
var r = Raphael('map', 750, 625),
attributes = {
fill: '#FFC000',
stroke: '#393738',
'stroke-width': 0,
'stroke-linejoin': 'round',
cursor: 'pointer'
},
attributes_circle = {
fill: '#fff',
stroke: '#393738',
'stroke-width': 0,
'stroke-linejoin': 'round'
},
attributes_line = {
fill: '#fff',
stroke: '#fff',
'stroke-width': 7,
'stroke-linejoin': 'round'
},
attributes_min_circle = {
fill: '#fff',
stroke: '#fff',
'stroke-width': 0,
'stroke-linejoin': 'round'
},
icon = {
fill: '#FFC000',
stroke: '#393738',
'stroke-width': 0,
'stroke-linejoin': 'round'
},
icon_inner = {
fill: '#fff',
stroke: '#393738',
'stroke-width': 0,
'stroke-linejoin': 'round'
}
arr = new Array();
var id = 23;
var a = 1;
for (var country in paths) {
var obj = r.path(paths[country].path);
//Init text
if(a <= 7){
var path_a = r.path(paths['part_' + a].path);
path_a.node.setAttribute("class","black_bor")
var sst = String(paths['part_' + a].desc);
labelPath( path_a, sst);
}
a++;
//Fill stroke
if(paths[country].name=='circle'){
obj.attr(attributes_circle);
}else if(paths[country].name=='line'){
obj.attr(attributes_line);
}else if(paths[country].name=='min_circle'){
obj.attr(attributes_min_circle);
}else if(paths[country].name=='icon_inner'){
obj.attr(icon_inner);
}else if(paths[country].name=='icon'){
obj.attr(icon);
}
else{
obj.attr(attributes);
}
arr[obj.id] = country;
//Hover on element
obj
.hover(function(){
if(paths[arr[this.id]].name=='part_1'){
textattrs = { 'font-size': 18, fill: '#fff', stroke: '#393738', 'stroke-width': 0, "text-anchor":"start", 'stroke-linejoin': 'round', 'font-family': 'Arial,Helvetica,sans-serif', cursor: 'pointer', 'font-weight': 'bold' };
var path_a = r.path(paths[arr[this.id]].path);
path_a.node.setAttribute("class","black_bor")
var sst = String(paths[arr[this.id]].desc);
labelPath( path_a, sst, textattrs);
this.animate({
fill: '#F3811E'
}, 0);
$(".img_behind").attr("src", paths[arr[this.id]].img);
}
}, function(){
if(paths[arr[this.id]].name=='part_1'){
var path_a = r.path(paths[arr[this.id]].path);
path_a.node.setAttribute("class","black_bor")
var sst = String(paths[arr[this.id]].desc);
labelPath( path_a, sst);
this.animate({
fill: attributes.fill
}, 0);
}
})
}
});
Any ideas on how can I solve this problems?
Here is my work.
Whole work on jsFiddle.
I don't understand the first problem, you may need to reexplain it a bit, which part isn't working ?
For the 2nd part, you need to add pointer-events: none to stop it stealing the event..
text { pointer-events: none; }
jsfiddle
If I'm understanding the first bit correct, I think you will need to remove the hoverout, and just change the hover to remove any existing hover effects ?