我创建了一个水平条形图。我已在后面的代码中从数据库生成条形图的数据。
我对条形图有两个问题:
条形图正在显示,但很少有重叠。我尝试过设置“barPadding”和“barMargin”,但这不起作用。
我想在每个条形图上显示标签,说明每个条形图代表什么。这些标签在后面的代码中从数据库中检索并存储在字符串数组中。这是条形图中的每个条形图,我想显示标签,如“帐户”,“电信”等。这些标签位于从后面的代码中的数据库中检索的数组中。
对上述查询的任何输入都将非常感激。
以下是JQPlot脚本
<script type="text/javascript">
function RunTest() {
$.jqplot.config.enablePlugins = true;
<% var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();%>
var industryName = <%= serializer.Serialize(arrIndustryName) %>
industryPostings = <%= serializer.Serialize(arrIndustryPostings)%>
plot = $.jqplot('dispStats', [industryPostings], {
captureRightClick: true,
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
showAngel: 135,
rendererOptions: {
barDirection: 'horizontal',
barMargin: 200,
barPadding: 500,
barWidth: 10,
highlightMouseDown: true
},
pointLabels: { show: true, formatString: '%d' }
},
legend: {
show: true,
location: 'e',
placement: 'outside'
},
axes: {
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
return false;
}
</script>
//asp.net button control to invoke code behind code and run the bar chart script
<asp:Button ID="btnTrends" runat="server" Text="Get Data" OnClick="GetPostingStatistics"
style="margin-right:10px"/>
<asp:Button ID="test" runat="server" Text="Show Trend" OnClientClick="return RunTest()" />
以下是守则背后的守则
protected void GetPostingStatistics(object sender, EventArgs e)
{
string strFromDate = txtFromDate.Text;
string strToDate = txtToDate.Text;
switch (ddlTrend.SelectedValue)
{
case "Industries":
{
//Code for Sql Connection
sql = "select Value from mpats_FieldValue where FieldID =15";
cmd = new SqlCommand(sql, conn);
adapter = new SqlDataAdapter(cmd);
postingRecords = new DataSet();
adapter.Fill(postingRecords);
List<string> industryNames = new List<string>();
// Code for retrieving labels against each bar from database
foreach (DataRow name in postingRecords.Tables[0].Rows)
{
industryNames.Add(name.Field<string>("Value"));
}
int[] numberOfPostings = new int[industryNames.Count];
for (int i = 0; i < industryNames.Count; i++)
{
sql = "select count(p.PostingId) as PostingsCount from
mpats_AdvertPosting p left join mpats_Advert a on p.AdvertID =
a.AdvertID " +
"where p.PostingStatusID between 400 and 451 " +
"and a.Industry = @Industry";
cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Industry", industryNames[i]);
adapter = new SqlDataAdapter(cmd);
postingRecords = new DataSet();
adapter.Fill(postingRecords);
numberOfPostings[i] = Convert.ToInt32(postingRecords.Tables
[0].Rows[0]
["PostingsCount"]);
}
arrIndustryName = industryNames.ToArray();
arrIndustryPostings =
numberOfPostings;
}
conn.Close();
break;
}
default:
{
break;
}
}
}
由于
Shwetha