function buildCharts(selection) {
  
    // Read the json data
    d3.json("samples.json").then((sampleData) => {
  
        // Filter the data to get the sample's OTU data
        var filtData = sampleData.samples;
        var sampleDict = filtData.filter(item => item.id == selection)[0];
        var sampleValues = sampleDict.sample_values; 
        var idValues = sampleDict.otu_ids;
        var barLabels = idValues.slice(0, 10).reverse();
        var newLabels = [];
        barLabels.forEach((label) => {
            newLabels.push("OTU " + label);
        });
        var hovertext = sampleDict.otu_labels;
        
        // Create bar chart in correct location
        var barTrace = {
            type: "bar",
            y: newLabels,
            x: sampleValues.slice(0, 10).reverse(),
            text: hovertext.slice(0, 10).reverse(),
            orientation: 'h'
        };
  
        var barData = [barTrace];
  
    // Create the layout variable
    var barLayout = {
      title: "Top 10 OTUs",
      yaxis: {
        tickmode: "linear"
      }
    };
  
        Plotly.newPlot("bar", barData, barLayout);
  
        // Create bubble chart in correct location
        var bubbleTrace = {
            x: idValues,
            y: sampleValues,
            text: hovertext,
            mode: "markers",
            marker: {
                color: idValues,
                size: sampleValues
            }
        };
  
        var bubbleData = [bubbleTrace];
  
        var layout = {
            showlegend: false,
            height: 600,
            width: 1000,
            xaxis: {
                title: "OTU ID"
            }
        };
  
        Plotly.newPlot("bubble", bubbleData, layout);
    });
  }
// Define a function that will create charts for given sample
Define a function that will create charts for given sample
Define a function that will create charts for given sample
function buildCharts(selection) {
    d3.json("samples.json").then((sampleData) => {
        var filtData = sampleData.samples;
        var sampleDict = filtData.filter(item => item.id == selection)[0];
        var sampleValues = sampleDict.sample_values; 
        var idValues = sampleDict.otu_ids;
        var barLabels = idValues.slice(0, 10).reverse();
        var newLabels = [];
        barLabels.forEach((label) => {
            newLabels.push("OTU " + label);
        });
        var hovertext = sampleDict.otu_labels;
        var barTrace = {
            type: "bar",
            y: newLabels,
            x: sampleValues.slice(0, 10).reverse(),
            text: hovertext.slice(0, 10).reverse(),
            orientation: 'h'
        };
        var barData = [barTrace];
    var barLayout = {
      title: "Top 10 OTUs",
      yaxis: {
        tickmode: "linear"
      }
    };
        Plotly.newPlot("bar", barData, barLayout);
        var bubbleTrace = {
            x: idValues,
            y: sampleValues,
            text: hovertext,
            mode: "markers",
            marker: {
                color: idValues,
                size: sampleValues
            }
        };
        var bubbleData = [bubbleTrace];
        var layout = {
            showlegend: false,
            height: 600,
            width: 1000,
            xaxis: {
                title: "OTU ID"
            }
        };
        Plotly.newPlot("bubble", bubbleData, layout);
    });
  }
function buildCharts ( selection ) { d3 . json ( "samples.json" ) . then ( ( sampleData ) => { var filtData = sampleData . samples ; var sampleDict = filtData . filter ( item => item . id == selection ) [ 0 ] ; var sampleValues = sampleDict . sample_values ; var idValues = sampleDict . otu_ids ; var barLabels = idValues . slice ( 0 , 10 ) . reverse ( ) ; var newLabels = [ ] ; barLabels . forEach ( ( label ) => { newLabels . push ( "OTU " + label ) ; } ) ; var hovertext = sampleDict . otu_labels ; var barTrace = { type : "bar" , y : newLabels , x : sampleValues . slice ( 0 , 10 ) . reverse ( ) , text : hovertext . slice ( 0 , 10 ) . reverse ( ) , orientation : 'h' } ; var barData = [ barTrace ] ; var barLayout = { title : "Top 10 OTUs" , yaxis : { tickmode : "linear" } } ; Plotly . newPlot ( "bar" , barData , barLayout ) ; var bubbleTrace = { x : idValues , y : sampleValues , text : hovertext , mode : "markers" , marker : { color : idValues , size : sampleValues } } ; var bubbleData = [ bubbleTrace ] ; var layout = { showlegend : false , height : 600 , width : 1000 , xaxis : { title : "OTU ID" } } ; Plotly . newPlot ( "bubble" , bubbleData , layout ) ; } ) ; }
Define a function that will create charts for given sample
Define a function that will create charts for given sample
// Read the json data // Filter the data to get the sample's OTU data // Create bar chart in correct location // Create the layout variable // Create bubble chart in correct location