What I am wanting to do is take data from two rows as x & y axis and that data should be displayed in a bar chart.
Here is what I am doing:
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Bar Chart Example <small>With custom colors.</small></h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li>
<a href="#">Config option 1</a>
</li>
<li>
<a href="#">Config option 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="flot-chart">
<div class="flot-chart-content" id="flot-bar-chart"></div>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
@Scripts.Render("~/plugins/flot")
<script type="text/javascript">
$(document).ready(function () {
var barOptions = {
series: {
bars: {
show: true,
barWidth: 0.6,
fill: true,
fillColor: {
colors: [{
opacity: 0.8
}, {
opacity: 0.8
}]
}
}
},
xaxis: {
tickDecimals: 0
},
colors: ["#1ab394"],
grid: {
color: "#999999",
hoverable: true,
clickable: true,
tickColor: "#D4D4D4",
borderWidth: 0
},
legend: {
show: false
},
tooltip: true,
tooltipOpts: {
content: "x: %x, y: %y"
}
};
var barData = {
label: "bar",
data: [ **//here i want to set a query to get data from database**
[1, 40],
[2, 25],
[3, 19],
[4, 34],
[5, 32],
[6, 22]
]
};
$.plot($("#flot-bar-chart"), [barData], barOptions);
var barOptions = {
series: {
lines: {
show: true,
lineWidth: 2,
fill: true,
fillColor: {
colors: [{
opacity: 0.0
}, {
opacity: 0.0
}]
}
}
},
xaxis: {
tickDecimals: 0
},
colors: ["#1ab394"],
grid: {
color: "#999999",
hoverable: true,
clickable: true,
tickColor: "#D4D4D4",
borderWidth: 0
},
legend: {
show: false
},
tooltip: true,
tooltipOpts: {
content: "x: %x, y: %y"
}
};
var barData = {
label: "bar",
data: [ **//here i want to set a query to get data from database**
[1, 40],
[2, 25],
[3, 19],
[4, 34],
[5, 32],
[6, 22]
]
};
doPlot("right");
$("button").click(function () {
doPlot($(this).text());
});
});
</script>
}
How to achieve it? Can I set a query here or should I manage this in controller? like this
E.g If I have a table in SQL named Sale and having two records "Sales & Year", I want to show years at x-axis and sales at y-axis.