【问题标题】:How to set specific color for each data in pie chart using phplot.php如何使用 phplot.php 为饼图中的每个数据设置特定颜色
【发布时间】:2015-09-10 06:49:22
【问题描述】:

在我的 php 页面中,我有值的下拉列表。对于每个选择的值,我必须为所选值显示一个饼图。我使用 phplot.php 绘制饼图。

我们有 setDataColor() 函数来设置颜色或默认颜色。但是下拉列表中的每个值都有相同的数据,但数字不同。例如,

Dropdown values:student1,student2,student3

在数据库中,

student1:**subj**   **marks**
          eng         10
          maths        0
          sci         30

student2: eng         20
          sci         40

student3: maths       50  

我想要颜色为 eng-'red',maths-'green',sci-'blue'

如果我们使用 phplot 函数 (setDatacolor()),我们可以将颜色作为数组 (red,green,blue) 传递。这不会为 student2 和 student3 饼图提供期望的输出,因为它只遵循顺序。

但我希望每次数学都是绿色的,科学是蓝色的等等。

有什么办法吗?

【问题讨论】:

    标签: php charts highcharts


    【解决方案1】:

    像下面这样:

    在下拉列表更改时调用函数,如下所示(要发送的下拉列表值)

    var chart_data = getChartData( Student, EngMarks, mathsMarks, scienceMarks);
                    var chart = new Highcharts.Chart( chart_data );
    
         xAxis : {  
                 categories : [ 
                        'English',
                         'Maths', 
                         'Science', 
                      ] },
    
         series : [ {                       type : 'pie',
                                            name : Student,
                                            data : [ 
    
                                                    {
                                                        name : 'English',
                                                        y : EngMarks,
                                                        color : 'Red'
                                                    },
                                                    {
                                                        name : 'Maths',
                                                        y : mathsMarks,
                                                        color : 'green'
                                                    },
                                                    {
                                                        name : 'Science',
                                                        y : scienceMarks,
                                                        color : 'blue'
                                                    } ]
                                        } ]
    

    【讨论】:

    • 我没有任何java脚本代码..我只使用php函数绘制饼图。
    • 告诉我们如何复制您的问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    • 1970-01-01
    相关资源
    最近更新 更多