图表饼图高清MVC ASP.net中的错误数据

时间:2014-03-03 02:26:20

标签: javascript asp.net asp.net-mvc charts highcharts

我在制作Highcharts风格的饼图时遇到了麻烦。我有以下代码来生成系列

        if (vlrTot1 >= 0)
        {
            Dictionary<string, object> aSeries = new Dictionary<string, object>();
            aSeries["data"] = new List<object[]>();
            aSeries["name"] = "TIR <= " + vlrLimInf.ToString();

            object[] values = new object[2];
            decimal vlr1 = Math.Round(((vlrTot1 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1);
            values[0] = "TIR <= " + vlrLimInf.ToString();
            values[1] = vlr1;
            ((List<object[]>)aSeries["data"]).Add(values);
            dataResult.Add(aSeries);

        }
        if (vlrTot2 >= 0)
        {
            Dictionary<string, object> aSeries = new Dictionary<string, object>();
            aSeries["data"] = new List<object[]>();
            aSeries["name"] = vlrLimInf.ToString() + " > TIR <= " + vlrLimSup.ToString();

            object[] values = new object[2];
            decimal vlr2 = Math.Round(((vlrTot2 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1);
            values[0] = vlrLimInf.ToString() + " > TIR <= " + vlrLimSup.ToString();
            values[1] = vlr2;
            ((List<object[]>)aSeries["data"]).Add(values);
            dataResult.Add(aSeries);

        }
        if (vlrTot3 >= 0)
        {
            Dictionary<string, object> aSeries = new Dictionary<string, object>();
            aSeries["data"] = new List<object[]>();
            aSeries["name"] = "TIR > " + vlrLimSup.ToString();

            object[] values = new object[2];
            decimal vlr3 = Math.Round(((vlrTot3 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1);
            values[0] = "TIR > " + vlrLimSup.ToString();
            values[1] = vlr3;
            ((List<object[]>)aSeries["data"]).Add(values);
            dataResult.Add(aSeries);

        }

但是,这会生成此图表。

enter image description here

前两个系列100%。

正确的图形必须是这样的:

enter image description here

下面是使用json生成图表的输出:

      var data = ServiceGraf.GetValuesByGrafPie(....PARAMETERS....);

                return Json(data, JsonRequestBehavior.AllowGet);

在索引中:

                function (data) {
                 var chart = new Highcharts.Chart({
                        chart: {
                            renderTo: 'container',
                            ignoreHiddenSeries: false,
                            type: graf,
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false

                        },
                        title: {
                            text: 'Gráfico do Levantamento de ' + levant
                        },
                        tooltip: {
                            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: false
                                },
                                showInLegend: true
                            }
                        },
                        series: data
                    });
                   }

我不知道这是错的。 下面是Json的输出值。 enter image description here

enter image description here

0 个答案:

没有答案