我希望它看起来像一个普通的饼图,但我不知道自己在做什么错,我尝试了不同的方法,但是所有这些方法都会产生不同的问题。
所以我在这里有2个错误,图例都一样,实际的饼图看起来很奇怪。
这是我的代码,已经搜索了一段时间,但似乎找不到实际的方法。我很确定我只是缺少一些超级简单的东西。
gr_pass_stats.Reset( All! )
//Populate Graph
int SNum
SNum = gr_pass_stats.AddSeries("Numeric")
gr_pass_stats.AddData(SNum, li_num, "Numeric") // Category is Numeric.
SNum = gr_pass_stats.AddSeries("Alphabetic")
gr_pass_stats.AddData(SNum, li_alph, "Alphabetic") // Category is Alphabetic.
SNum = gr_pass_stats.AddSeries("Combo")
gr_pass_stats.AddData(SNum, li_combo, "Combo") // Category is Combo.
SNum = gr_pass_stats.AddSeries("Wordlist")
gr_pass_stats.AddData(SNum, li_word, "Wordlist") // Category is Wordlist.
SNum = gr_pass_stats.AddSeries("Wordnum")
gr_pass_stats.AddData(SNum, li_word_num, "Wordnum") // Category is Wordnum.
答案 0 :(得分:-1)
将此粘贴到设计页面中。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var options = {
title: 'CHART',
width: 400,
height: 400,
bar: { groupWidth: "95%" },
legend: { position: "none" },
isStacked: true
};
$.ajax({
type: "POST",
url: "Chart.aspx/GetChartData", //Chart.aspx is the page name.
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
debugger;
var data = google.visualization.arrayToDataTable(r.d);
var chart = new google.visualization.PieChart($("#chart")[0]); //***PieChart***
chart.draw(data, options);
},
failure: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.d);
}
});
}
</script>
<div id="chart" style="width: 500px; height: 500px;"> //this is the div which shows the chart.
</div>
将此粘贴到您的c#页面中。
using System.Web.Services;
[WebMethod]
public static List<object> GetChartData()
{
string query = "select Share,Value from Table";
string constr = ConfigurationManager.ConnectionStrings["dbcn"].ConnectionString;
List<object> chartData = new List<object>();
chartData.Add(new object[]
{
"Share", "Value"
});
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
chartData.Add(new object[]
{
sdr["Share"], sdr["Value"]
});
}
}
con.Close();
return chartData;
}
}
}