JavaScript中如何使用dhtmlxChart图表组件
更新:HHH   时间:2023-1-7


今天就跟大家聊聊有关JavaScript中如何使用dhtmlxChart图表组件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

dhtmlxChart的配置

在页面上引用dhtmlx的相关js脚本和css文件即可完成安装:

<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
<script src="../../../codebase/dhtmlx.js"></script>

路径需要你自己修改。

另外dhtmlxChart提供了4种数据源格式,支持XML、JSON、CSV以及JS数组,以XML为例:

window.onload = function(){
        var barChart =  new dhtmlXChart({
            view:"bar",
            container:"chartDiv",
            value:"#sales#",
            gradient:"falling",
            color:"#b9a8f9",
            radius:0,
            alpha:0.5,
            border:true,
            width:70,
            xAxis:{
                template:"#year#"
            },
            yAxis:{
                start:0,
                end:100,
                step:10,
                template:function(obj){
                    return (obj%20?"":obj)
                }
            }
        })
        barChart.load("../common/data.xml");
}

dhtmlxChart柱形图生成

window.onload = function(){
var barChart1 =  new dhtmlXChart({
view:"bar",
container:"chart1",
    value:"#sales#",
        label:"'#year#",
        barWidth:35,
        radius:0,
        gradient:"rising"
})
barChart1.parse(dataset,"json");
barChart1.attachEvent("onItemClick",function(id){alert(id)})
var barChart2 =  new dhtmlXChart({
view:"bar",
container:"chart2",
    value:"#sales#",
        label:"'#year#",
        color:"#66ccff",
        gradient:"rising",
        barWidth:25,
        padding:{
            top:50,
            bottom:0,
            right:50,
            left:50
        }
});
barChart2.parse(dataset,"json");
}

这里就使用了json的数据格式。

效果图如下:

dhtmlxChart雷达点图生成

var chart =  new dhtmlXChart({
            container:"chartDiv",
            view:"radar",
value:"#companyA#",
            disableLines:true,
item:{
                borderWidth:0,
                radius:2,
color: "#6633ff"
},
xAxis:{
template:"#month#"
},
yAxis:{
lineShape:"arc",
                bg:"#fff8ea",
                template:function(value){
                    return parseFloat(value).toFixed(1)
                }
}
        });
        chart.parse(companies,"json");

效果图如下:

dhtmlxChart离散点图生成

chart =  new dhtmlXChart({
            view:"scatter",
container:"chartDiv",
    value:"#b#",
xValue: "#a#",
            yAxis:{
                title:"Value B"
            },
            xAxis:{
                title:"Value A"
            },
            tooltip:{
              template:"#a# - #b#"
            },
            item:{
                radius:5,
                borderColor:"#f38f00",
                borderWidth:1,
                color:"#ff9600",
                type:"d",
                shadow:true
            }
        });
chart.parse(scatter_dataset,"json");

效果图如下:

看完上述内容,你们对JavaScript中如何使用dhtmlxChart图表组件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。

返回web开发教程...