树状图-HierarchicalDataSource-模板

时间:2019-06-11 18:21:51

标签: jquery kendo-ui

我正在将Kendo UI的树形图与分层数据源一起使用。我尝试使用colorField配置更改正方形的颜色,但没有更改颜色。

因此,我决定我不仅要尝试使用模板来对齐一些文本,还要根据数据源中的字段设置import pandas as pd import matplotlib.pyplot as plt import numpy as np import tensorflow as tf import logging get_ipython().run_line_magic('matplotlib', 'inline') tf.logging.set_verbosity(tf.logging.INFO) #import data df = pd.read_csv('Dataset.csv') df2=pd.read_csv('Cosmolabel.csv') #data we want to test df3 = pd.read_csv('Testset.csv') x_try=df3.iloc[:,0:61] y_tryAC1=df3['AC1'] x_data=df y_valAC1=df2['AC1'] from sklearn.model_selection import train_test_split X_train, X_test, y_trainAC1, y_testAC1 = train_test_split(x_data,y_valAC1,test_size=0.3,random_state=101) feat_cols=[evap,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32,C33,C34,C35,C36,C37,C38,C39,C40,C41,C42,C43,C44,C45,C46,C47,C48,C49,C50,C51,C52,C53,C54,C55,C56,C57,C58,C59,C60] #define model and trein input_funcAC1=tf.estimator.inputs.pandas_input_fn(x=X_train,y=y_trainAC1,batch_size=10,num_epochs=100000,shuffle=True) modelAC1=tf.estimator.DNNRegressor(activation_fn=tf.nn.relu, hidden_units=[1024,521,256,128,64],feature_columns=feat_cols,model_dir='Model_folder_AC1', optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.1, l1_regularization_strength=0.001)) modelAC1.train(input_fn=input_funcAC1,steps=10000) #Evaluate the model with training data eval_input_func = tf.estimator.inputs.pandas_input_fn(X_test, y_test, batch_size=1, num_epochs=1, shuffle=False) model.evaluate(input_fn=eval_input_func) #now use the external data for analysis try_input_func = tf.estimator.inputs.pandas_input_fn( x=x_try, batch_size=10, num_epochs=1, shuffle=False) try_genAC1=modelAC1.predict(try_input_func) #now to simulate a loop I would like te use predictions=[] for i in range(0,10): try_genAC1=modelAC1.predict(try_input_func) tryingAC1=list(try_genAC1) for j in range(0,len(tryingAC1),1): pred=float(tryingAC1[j].get('predictions')) predictions.append(pred) print(predictions) 。但是,然后我遇到一个问题,即它在控制台中指示未定义我的background-color字段,因此我尝试仅删除该引用,而仅引用Color字段(这就是我m在textField配置中设置),但发生了相同的错误。

奇怪的是,如果我删除模板,那么它将正确地呈现文本,只是无法呈现正确的背景颜色。

这就是我要使用的:

Name
$(document).ready(function() {
  var data = [
    {
      "Name": "CEO",
      "Color": "#e6a800",
      "Children": [
        {
          "Name": "CFO",
          "Level": 3,
          "Color": "#9dddf2",
          "Children": [
            {
              "Name": "Comptroller",
              "Level": 2,
              "Color": "#4db85f",
              "Children": [
                {
                  "Name": "Lead Accountant",
                  "Level": 1,
                  "Color": "#d64d4d",
                  "Children": [
                    {
                      "Name": "Accountant",
                      "Level": 0,
                      "Color": "#c8ccdb"
                    },
                    {
                      "Name": "Clerk",
                      "Level": 0,
                      "Color": "#c8ccdb"
                    }
                  ]
                }
              ]
            },
            {
              "Name": "Senior Auditor",
              "Level": 1,
              "color": "#4db85f",
              "Children": [
                {
                  "Name": "Auditor",
                  "Level": 0,
                  "Color": "#c8ccdb"
                }
              ]
            }
          ]
        },
        {
          "Name": "COO",
          "Level": 3,
          "Color": "#9dddf2",
          "Children": [
            {
              "Name": "VP Of Operations",
              "Level": 2,
              "Color": "#4db85f",
              "Children": [
                {
                  "Name": "Field Manager",
                  "Level": 1,
                  "Color": "#4d69d6",
                  "Children": [
                    {
                      "Name": "Field Adjuster",
                      "Level": 0,
                      "Color": "#c8ccdb"
                    }
                  ]
                },
                {
                  "Name": "Home Office Manager",
                  "Level": 1,
                  "Color": "#4d69d6",
                  "Children": [
                    {
                      "Name": "Desk Adjuster",
                      "Level": 0,
                      "Color": "#c8ccdb"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ];
  $("#treeMap").kendoTreeMap({
    dataSource: new kendo.data.HierarchicalDataSource({
      data: data,
      schema: {
        model: {
          children: "Children",
          hasChildren: "Children"
        }
      }
    }),
    colorField: "Color",
    valueField: "Level",
    textField: "Name",
    type: 'Vertical',
    //template: kendo.template($('#organizationalHierarchyTemplate').html())
  });
});

提琴:Live Demo

1 个答案:

答案 0 :(得分:1)

您的级别用于确定每个正方形的面积,并且在您向上移动层次结构时需要累加。例如

    var data = [
      {
        "Name": "CEO",
        "Color": "#e6a800",
        "Level": 17,
        "Children": [
          {
            "Name": "CFO",
            "Color": "#9dddf2",
            "Level": 11,
            "Children": [
              {
                "Name": "Comptroller",
                "Color": "#4db85f",
                "Level": 3,
                "Children": [
                  {
                    "Name": "Lead Accountant",
                    "Color": "#d64d4d",
                    "Level": 3,
                    "Children": [
                      {
                        "Name": "Accountant",
                        "Level": 2,
                        "Color": "#c8ccdb"
                      },
                      {
                        "Name": "Clerk",
                        "Level": 1,
                        "Color": "#cdefdc"
                      }
                    ]
                  }
                ]
              },
              {
                "Name": "Senior Auditor",
                "color": "#4db85f",
                "Level": 8,
                "Children": [
                  {
                    "Name": "Auditor",
                    "Level": 8,
                    "Color": "#c8ccdb"
                  }
                ]
              }
            ]
          },
          {
            "Name": "COO",
            "Color": "#9dddf2",
            "Level": 6,
            "Children": [
              {
                "Name": "VP Of Operations",
                "Color": "#4db85f",
                "Level": 6,
                "Children": [
                  {
                    "Name": "Field Manager",
                    "Color": "#4d69d6",
                    "Level": 2,
                    "Children": [
                      {
                        "Name": "Field Adjuster",
                        "Level": 2,
                        "Color": "#c8ccdb"
                      }
                    ]
                  },
                  {
                    "Name": "Home Office Manager",
                    "Color": "#4d69d6",
                    "Level": 4,
                    "Children": [
                      {
                        "Name": "Desk Adjuster",
                        "Level": 4,
                        "Color": "#c8ccdb"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ];

在模板中,您从dataItem对象获取字段

  <script id="organizationalHierarchyTemplate" type="text/x-kendo-template">
    <div style="height: auto; background-color: #= dataItem.Color #;">
        <p style="text-align: center;">#: dataItem.Name #</p>
    </div>
  </script>