Related
With this simple List, the listRowInsets modifier works as expected (the color red has no inset in the list row):
struct ContentView: View {
var body: some View {
List {
Color.red
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
However, if the List is instantiated with a data parameter, listRowInsets stops working:
struct ContentView: View {
var body: some View {
List(0 ..< 1) { _ in
Color.red
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
How do I get the content of a list item to have no inset in the second example?
Use List with ForEach, like below
List {
ForEach(0 ..< 1) { _ in
Color.red
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
I have a ListView.builder that creates several containers. it is used for filtering products by color in an eCommerce app. I want to give the containers border when the user taps the color. it looks something like this:
https://dribbble.com/shots/5569127
here is what I have tried now, but it does not give border to the containers on every click:
Color tileColor = Colors.lime;
List<String> availableColors = ["red", "blue", "black", "brown", "violet"];
Container(
height: 50,
width: double.infinity,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: availableColors.length,
itemBuilder: (BuildContext context, int index) {
bool showBorder = false;
if (availableColors[index] == "red") {
tileColor = Colors.red;
}
if (availableColors[index] == "blue") {
tileColor = Colors.blue;
}
if (availableColors[index] == "black") {
tileColor = Colors.black;
}
if (availableColors[index] == "brown") {
tileColor = Colors.brown;
}
return Padding(
padding: const EdgeInsets.only(left: 10),
child: GestureDetector(
onTap: () {
setState(() {
print("object");
showBorder = !showBorder;
print(showBorder);
});
},
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: tileColor,
border: showBorder ? Border.all(color: Colors.green , width: 5) : Border(),
shape: BoxShape.circle),
),
),
);
},
),
)
As commented by #pskink: use - int showBorder instead of bool showBorder
Code:
int showBorder = 999999999;
List<String> availableColors = ["red", "blue", "black", "brown", "violet"];
#override
Widget build(BuildContext context) {
return Container(
height: 50,
width: double.infinity,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: availableColors.length,
itemBuilder: (BuildContext context, int index) {
if (availableColors[index] == "red") {
tileColor = Colors.red;
}
if (availableColors[index] == "blue") {
tileColor = Colors.blue;
}
if (availableColors[index] == "black") {
tileColor = Colors.black;
}
if (availableColors[index] == "brown") {
tileColor = Colors.brown;
}
return Padding(
padding: const EdgeInsets.only(left: 10),
child: GestureDetector(
onTap: () {
setState(() {
print(index);
showBorder = index;
});
},
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: tileColor,
border: showBorder == index
? Border.all(color: Colors.green, width: 5)
: Border(),
shape: BoxShape.circle),
),
),
);
},
),
);
For multiple selections. You have to save the tap index in the list.
Code:
// int showBorder = 999999999;
List listBorder = [];
List<String> availableColors = ["red", "blue", "black", "brown", "violet"];
#override
Widget build(BuildContext context) {
listBorder.length = availableColors.length;
return Center(
child: Container(
height: 50,
width: double.infinity,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: availableColors.length,
itemBuilder: (BuildContext context, int index) {
if (availableColors[index] == "red") {
tileColor = Colors.red;
}
if (availableColors[index] == "blue") {
tileColor = Colors.blue;
}
if (availableColors[index] == "black") {
tileColor = Colors.black;
}
if (availableColors[index] == "brown") {
tileColor = Colors.brown;
}
return Padding(
padding: const EdgeInsets.only(left: 10),
child: GestureDetector(
onTap: () {
setState(() {
print(index);
listBorder.insert(index, index);
// showBorder = index;
print(listBorder[index]);
});
},
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: tileColor,
border: listBorder[index] == index
? Border.all(color: Colors.green, width: 5)
: Border(),
shape: BoxShape.circle),
),
),
);
},
),
),
);
I use Highcharts to visualize my data. Recently I found that when I move my mouse around the chart, part of the chart will be missing. Looks like it happens randomly and I have no idea what triggers it.
I created a jsfiddle example here with js codes below:
Highcharts.chart('container', {
credits: {
enabled: false
},
title: {
text: "资产结构"
},
tooltip: {
enabled: true,
shared: true
},
xAxis: [{
categories: ['2014年', '2015年', '2016年', '2017年半年度'],
crosshair: true
}],
yAxis: [{
title: {
text: "金额(万元)",
style: {
color: "#33C4FF"
}
},
labels: {
format: "{value:,.0f}",
style: {
color: "#33C4FF"
}
},
opposite: false
}, {
title: {
text: "比率(倍)",
style: {
color: "#99FF33"
}
},
labels: {
format: "{value}",
style: {
color: "#99FF33"
}
},
opposite: true
}],
plotOptions: {
area: {
stacking: 'normal'
},
series: {
shadow: true
}
},
legend: {
enabled: true,
backgroundColor: Highcharts.theme && Highcharts.theme.legendBackgroundColor || '#FFFFFF'
},
series: [{
name: "流动资产",
yAxis: 0,
data: [{
color: "#33C4FF",
y: -0.01,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: "资产总额",
SharedTooltipExtraValue: "1.69"
}, {
color: "#33C4FF",
y: 0.81,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: "资产总额",
SharedTooltipExtraValue: "306329.90"
}, {
color: "#33C4FF",
y: 0.01,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: "资产总额",
SharedTooltipExtraValue: "390056.33"
}, {
color: "#33C4FF",
y: 0.07,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: "资产总额",
SharedTooltipExtraValue: "0.09"
}],
type: "area",
color: "#33C4FF",
marker: {
symbol: "circle"
}
}, {
name: "非流动资产",
yAxis: 0,
data: [{
color: "#FFE333",
y: 1.68,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#FFE333",
y: 306329.79,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#FFE333",
y: 390056.32,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#FFE333",
y: 0.02,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}],
type: "area",
color: "#FFE333",
marker: {
symbol: "circle"
}
}, {
name: "流动比率",
yAxis: 1,
data: [{
color: "#99FF33",
y: -4.03,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#99FF33",
y: 23.44,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#99FF33",
y: 0,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#99FF33",
y: 1.19,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}],
type: "spline",
color: "#99FF33",
marker: {
symbol: "circle"
}
}, {
name: "速动比率",
yAxis: 1,
data: [{
color: "#33FFC4",
y: -6.32,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#33FFC4",
y: 23.25,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#33FFC4",
y: 0,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}, {
color: "#33FFC4",
y: 1.06,
Label: null,
radius: null,
innerRadius: null,
SharedTooltipExtraName: null,
SharedTooltipExtraValue: null
}],
type: "spline",
color: "#33FFC4",
marker: {
symbol: "circle"
}
}]
});
#container {
min-width: 310px;
max-width: 800px;
height: 400px;
margin: 0 auto
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/themes/dark-unica.js"></script>
<div id="container"></div>
Open it in Microsoft edge and then move the mouse around the yellow point on category '2016年'. Keep doing that for about 5 seconds, you should be able to see the issue.
I also record a video about the issue here: youtube link, any words are appreciated.
-- Update --
I tested the jsfiddle example on Microsoft Edge 40.15063.674.0, it works well. In the youtube video, the version of Edge is 41.16299.15.0, I am not sure if this is related.
How can I revert my theme back to the default one in Highcharts after I have applied some theme?
I tried this but doesn't work.
Highcharts.theme = {
};
var highchartsOptions = Highcharts.setOptions(Highcharts.theme);
I tried also the solution described here
removing all of the color options from the code below and reloading
the Highcharts object will make it default to the basic theme
...but it doesn't work either.
Thanks
Unforunately you need to overwrite all colors / parameters with default values for a second chart.
http://jsfiddle.net/WNGpQ/2/
var theme = {
colors: ['#2f7ed8', '#0d233a', '#8bbc21', '#910000', '#1aadce', '#492970',
'#f28f43', '#77a1e5', '#c42525', '#a6c96a'],
chart: {
backgroundColor: '#fff',
borderWidth: 0,
plotBackgroundColor: '#fff',
plotShadow: false,
plotBorderWidth: 0
},
title: {
style: {
color: '#274b6d',//#3E576F',
fontSize: '16px'
}
},
subtitle: {
style: {
color: '#4d759e'
}
},
xAxis: {
gridLineWidth: 0,
lineColor: '#C0D0E0',
tickColor: '#C0D0E0',
labels: {
style: {
color: '#666',
cursor: 'default',
fontSize: '11px',
lineHeight: '14px'
}
},
title: {
style: {
color: '#4d759e',
fontWeight: 'bold'
}
}
},
yAxis: {
minorTickInterval: null,
lineColor: '#C0D0E0',
lineWidth: 1,
tickWidth: 1,
tickColor: '#C0D0E0',
labels: {
style: {
color: '#666',
cursor: 'default',
fontSize: '11px',
lineHeight: '14px'
}
},
title: {
style: {
color: '#4d759e',
fontWeight: 'bold'
}
}
},
legend: {
itemStyle: {
color: '#274b6d',
fontSize: '12px'
},
itemHoverStyle: {
color: '#000'
},
itemHiddenStyle: {
color: '#CCC'
}
},
labels: {
style: {
color: '#3E576F'
}
},
navigation: {
buttonOptions: {
theme: {
stroke: '#CCCCCC'
}
}
}
};
I generate a stacked bar graph with Highcharts, and I have a problem with my interval between labels.
My data interval is only 6 and the labels interval generated by highchart is 100, see demo here : http://jsfiddle.net/NjaEw/2/
I want a label interval corresponding from data.
Here the code :
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<h1>Testing</h1>
<div id="conformity-by-page" style="width: 100%; height:250px; margin: 0 auto"></div>
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'conformity-by-page',
type: 'bar',
borderWidth: 1,
borderColor: '#000',
borderRadius: 0,
marginTop: 50
},
exporting: {
enabled: false
},
title: {
text: ''
},
xAxis: {
lineWidth:5,
categories: ['Web site'],
//tickWidth: 0,
title: {
text: null
},
labels: {
style: {
color: '#000000',
fontWeight: 'bold',
fontSize: '14px'
}
}
},
yAxis: {
lineWidth:0,
title: {
text: 'Number of page',
align: 'high',
style: {
color: '#000000',
fontSize: '16px'
}
},
labels: {
overflow: 'justify',
style: {
color: '#000000',
fontWeight: 'bold',
fontSize: '14px'
}
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y +' règles';
},
backgroundColor: '#FFFFFF',
style: {
color: '#000',
fontSize: '14px',
padding: '5px'
}
},
plotOptions: {
bar: {
borderColor: '#000000',
borderWidth: 1,
/*minPointLength: 10,*/
pointWidth: 25,
stacking: 'percent',
dataLabels: {
enabled: true
}
}
},
legend: {
verticalAlign: 'top',
backgroundColor: '#FFFFFF',
reversed: true,
shadow: true,
symbolWidth: 50,
itemStyle: {
color: '#000000',
fontSize: '15px'
}
},
credits: {
enabled: false
}, series: [{
name: 'Warning',data: [null], color: '#FFFF40',
dataLabels: {
style: {
fontSize: '15px',
color: '#000000'
}
}
}, {
name: 'Error',data: [3], color: '#FF8080',
dataLabels: {
style: {
fontSize: '15px',
color: '#000000'
}
}
}, {
name: 'N/A',data: [1], color: '#B5EBFB',
dataLabels: {
style: {
fontSize: '15px',
color: '#000000'
}
}
}, {
name: 'OK',data: [2], color: '#80FF80',
dataLabels: {
style: {
fontSize: '15px',
color: '#000000'
}
}
}]
});
});
The problem is that you're using stacking: 'percent'.
Change it to 'normal'.
Demo