在条形图ChartJs 2.1.6上显示数据集值

时间:2016-07-28 11:40:48

标签: javascript chart.js

根据chartjs版本已更改,条形图上显示的数据集值无法正常工作。现有代码已与V1.0.2配合使用。 参考:how to display data values on Chart.js



var ctx = document.getElementById("myChart2").getContext("2d");
var myBar = new Chart(ctx).Bar(chartData, {
    showTooltips: false,
    onAnimationComplete: function () {

        var ctx = this.chart.ctx;
        ctx.font = this.scale.font;
        ctx.fillStyle = this.scale.textColor
        ctx.textAlign = "center";
        ctx.textBaseline = "bottom";

        this.datasets.forEach(function (dataset) {
            dataset.bars.forEach(function (bar) {
                ctx.fillText(bar.value, bar.x, bar.y - 5);
            });
        })
    }
});




现在将对ChartJs V2.1.6进行哪些修改? 当前条形图语法与下面给出的V2.1.6一起使用。



        var myBarChart = new Chart(ctx, {
            type: 'bar',
            data: datasets,
            options: {
                responsive: true,
                tooltips: {
                    enabled: false
                },
                legend: {
                    display: false
                },
              //what should add to display values on bar?
            }
        });




1 个答案:

答案 0 :(得分:0)

使用@Override public void onResponse(String response) { try { JSONObject jObject = new JSONObject(response); JSONArray jsonArray = jObject.getJSONArray("cart"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jbjct = jsonArray.getJSONObject(i); ItemProductList itemListModel = new ItemProductList(); itemListModel.thickness1 = jbjct.getString("thickness"); itemListModel.id1 = jbjct.getString("id"); itemListModel.price1 = jbjct.getString("price"); itemListModel.category1 = jbjct.getString("category"); itemListModel.name1=jbjct.getString("name"); itemListModel.sr_no=jbjct.getString("sr_no"); values1.add(itemListModel); } //Check if list is empty or not if(values1.size()>0){ mAdapter= new ItenProductAdapter(context,values1); list_productlist.setAdapter(mAdapter); } } catch (JSONException e) { e.printStackTrace(); } } 键,如下所示:

SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent
FROM
(SELECT DISTINCT *,
 ROW_NUMBER() OVER 
 (
    PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority]
 ) 
 AS ranker 
 FROM #GroupMasterNameChoose
)Z
WHERE ranker = 1
ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]

http://www.chartjs.org/docs/#chart-configuration-animation-configuration