amchart - 传递参数性能/重复使用性能跨越图/使用多个图形相同的属性 [英] amchart - pass parameters to properties/reuse properties across graphs/Use same property across multiple graphs

查看:225
本文介绍了amchart - 传递参数性能/重复使用性能跨越图/使用多个图形相同的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的code我用它来绘制折线图。

Here's the code I use to plot a line graph.

var db_query = <?php echo json_encode($db_query_1) ?>;
var chart;
var graph;

/* chart initialization */
var chart = AmCharts.makeChart("plot1", {
    type: "serial",
    categoryField: "OCCUR_DATE",
    graphs: [{
        type: "smoothedLine",
        theme: "light",
        valueField: "FREQ"
    }]
})

$.ajax({
    type: 'POST',       
    url: "mySQL.php",
    data: {'db_que': db_query},
    dataType: 'html',
    context: document.body,
    global: false,
    async:true,
    success: function(data) {
        //alert(data);
        chart.dataProvider = eval(data);
        chart.validateNow();
    }
});

我想

  1. 创建一个单独的JavaScript文件的每一行,饼图,条形图等定义的属性类型的图表和放大器;导入javascript文件
  2. 替换这样的:

  1. Create a separate javascript file with properties defined for each of line, pie, bar etc types of graphs & import that javascript file
  2. replace this:

var chart = AmCharts.makeChart("plot1", {
    type: "serial",
    categoryField: "OCCUR_DATE",
    graphs: [{
        type: "smoothedLine",
        theme: "light",
        valueField: "FREQ"
    }]
})

var chart = AmCharts.makeChart("plot1", options_line_graph);

  • 我希望能够传递参数给的属性 x轴和安培; y轴标题和放大器;图名。这些是至少非常 一些可变参数我现在能想到的。如果我能做到这一点, 增加更多的可变参数可以很容易地做到我presume。

  • I'd like to be able to pass parameters to the properties for the x-axis & y-axis titles & the graph name. These are at least the very few variable parameters I can think of now. If I can achieve this, adding more variable parameters could be done easily I presume.

    我寻求帮助这里的原因,我有超过30线图,20饼图和放​​大器;一些其他类型的,我将绘制的。设置同一组属性上与放大器;一遍又一遍的声音做事效率低下的方式。

    The reason I ask for help here is, I have over 30 line graphs, 20 pie charts & a few of other types that I will plot. Setting the same set of properties over & over again sounds an inefficient way of doing things.

    可能有人请指导/帮助我?

    Could someone please guide/help me?

    推荐答案

    图表实例重用你传递的配置对象,所以,当然,你不能在同一个对象传递给多个图表。

    The chart instance reuses the object you pass in as configuration, so, naturally, you cannot pass in the same object to multiple charts.

    你能做什么,虽然是采用的修改和传递图表实例之前,通过在复制的配置对象。

    What you can do, though, is to pass in duplicated the config object before applying modifications and passing in to chart instance.

    有一个在这太线程。

    所以基本上你可以做这样的事情:

    So basically you could do something like this:

    // define universal config
    var universalConfig = {...};
    
    // clone universalConfig
    var instanceConfig1 = clone(universalConfig);
    
    // make modifications
    instaceConfig1.categoryField = "OCCUR_DATE";
    
    // create the chart
    var chart = AmCharts.makeChart("plot1", instaceConfig1);
    
    // repeat
    // ...
    

    下面是一个工作的例子在codePEN

    这篇关于amchart - 传递参数性能/重复使用性能跨越图/使用多个图形相同的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆