0

I am currently working on a middleware application using JSF and primefaces and I have a module to develop which concerns statistical reports

In fact, I have to automatically generate a graph for each asset which includes some information something like that:
enter image description here

First, I started by creating a view that contains all the information I need:
enter image description here

What I'm trying to do is to generate a RadarChart for each asset automatically. For example, if an asset is added to my application, it should appear. The problem is that I don't know how to start.

First, I created a method that returns the values ​​I need:

public ArrayList<risk> getGet_all_risk_for_radar_chart2() throws Exception{
    ArrayList<risk> rr = new ArrayList<>();
    Connection connection = null;
    try{

        DB_connection1 obj_DB_connection = new DB_connection1();
        connection = obj_DB_connection.get_connection();
        PreparedStatement ps = connection.prepareStatement("select risks_to_assets.risk_id , asset_id , calculated_risk , mitigation_percent from risks_to_assets INNER JOIN risk_scoring ON risks_to_assets.risk_id=risk_scoring.id INNER JOIN mitigations ON risks_to_assets.risk_id=mitigations.risk_id  ");
        ResultSet rs = ps.executeQuery();
        while(rs.next()){
            risk r = new risk();
            r.setRisk_id(rs.getInt("risk_id"));
            r.setId(rs.getInt("asset_id"));
            r.setCalculated_risk(rs.getInt("calculated_risk"));
            r.setMitigation_percent(rs.getInt("mitigation_percent"));
            rr.add(r);
        }

    
    }catch(Exception e){
        e.printStackTrace();

    }finally {
        if (connection != null) {
            connection.close();
        }
    }
    return rr;
}

I made a graph, but it contains all the assets:

enter image description here

Voila le code du graphe :

public void createRadarModel0()  {
    radarModel0 = new RadarChartModel();
    ChartData data = new ChartData();
    risk rr = new risk();

    RadarChartDataSet radarDataSet = new RadarChartDataSet();
    radarDataSet.setLabel("My First Dataset");
    radarDataSet.setFill(true);
    radarDataSet.setBackgroundColor("rgba(255, 99, 132, 0.2)");
    radarDataSet.setBorderColor("rgb(255, 99, 132)");
    radarDataSet.setPointBackgroundColor("rgb(255, 99, 132)");
    radarDataSet.setPointBorderColor("#fff");
    radarDataSet.setPointHoverBackgroundColor("#fff");
    radarDataSet.setPointHoverBorderColor("rgb(255, 99, 132)");
    List<Number> dataVal = new ArrayList<>();
   
   try{
  for(int i=0;i<rr.getGet_all_risk_for_radar_chart2().size();i++){
      dataVal.add(rr.getGet_all_risk_for_radar_chart2().get(i).getCalculated_risk());
     // System.out.println(rr.getGet_all_risk_for_radar_chart2().get(i).getCalculated_risk());
      radarDataSet.setData(dataVal);
  }
   }catch(Exception e){
       System.out.println(e);
   }
    RadarChartDataSet radarDataSet2 = new RadarChartDataSet();
    radarDataSet2.setLabel("My Second Dataset");
    radarDataSet2.setFill(true);
    radarDataSet2.setBackgroundColor("rgba(54, 162, 235, 0.2)");
    radarDataSet2.setBorderColor("rgb(54, 162, 235)");
    radarDataSet2.setPointBackgroundColor("rgb(54, 162, 235)");
    radarDataSet2.setPointBorderColor("#fff");
    radarDataSet2.setPointHoverBackgroundColor("#fff");
    radarDataSet2.setPointHoverBorderColor("rgb(54, 162, 235)");
    List<Number> dataVal2 = new ArrayList<>();
    try{
    rr.getGet_all_risk_for_radar_chart2();
    for(int i=0;i<rr.getGet_all_risk_for_radar_chart2().size();i++){
     dataVal2.add(rr.getGet_all_risk_for_radar_chart2().get(i).getMitigation_percent());
        radarDataSet2.setData(dataVal2);
  } 
    }catch(Exception e){
        System.out.println(e);
    }        
    data.addChartDataSet(radarDataSet);
    data.addChartDataSet(radarDataSet2);

    List<String> labels = new ArrayList<>();
    try{
    rr.getGet_all_risk_for_radar_chart2();
    for(int i=0;i<rr.getGet_all_risk_for_radar_chart2().size();i++){
        System.out.println(rr.getGet_all_risk_for_radar_chart2().get(i).getRisk_id());
     labels.add(String.valueOf(rr.getGet_all_risk_for_radar_chart2().get(i).getRisk_id()));
      data.setLabels(labels);
  }
    
    }catch(Exception e){
        System.out.println(e);
    }

    /* Options */
    RadarChartOptions options = new RadarChartOptions();
    Elements elements = new Elements();
    ElementsLine elementsLine = new ElementsLine();
    elementsLine.setTension(0);
    elementsLine.setBorderWidth(3);
    elements.setLine(elementsLine);
    options.setElements(elements);

    radarModel0.setOptions(options);
    radarModel0.setData(data);
}

I hope someone can explain the process to make it appear automatically for every assets.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Loran
  • 35
  • 5
  • I'm confused. Your title is different to what you explain in your question. Please improve. – Jasper de Vries Jun 23 '22 at 07:57
  • I did a change on my question now , this what i really want do and its explained if If you dont understand a part, let me know so I'll detail it more – Loran Jun 23 '22 at 08:17
  • are you saying instead of ALL the assets you just want a single Asset displayed in the Chart? – Melloware Jun 23 '22 at 11:56
  • @Melloware some how yes , i want only a single Asset in the Chart , and i want to generate it automatically example : if an asset is created , the graph of this asset should appears in my page auto – Loran Jun 23 '22 at 13:27
  • Then why not just create a method that gets 1 asset instead of getting all your assets? – Melloware Jun 23 '22 at 13:39
  • and how can i generate others asset ? if i do that i have to create the radarChart code for every asset – Loran Jun 23 '22 at 13:59
  • https://stackoverflow.com/questions/9186364/how-do-i-display-a-list-of-items-from-a-bean-onto-a-jsf-webpage – Jasper de Vries Jun 23 '22 at 15:06

0 Answers0