Problem in rendering Multiple Drilldown in fusioncharts

我的梦境 提交于 2019-12-24 07:58:10

问题


I am using Django. I want use the drilldown feature in fusioncharts. I am able to get the first drilldown correctly. But when I code for the second drilldown it is showing "No data to display". Also the following code renders all the charts in the same type. But I want to render the child charts in different types. I am sharing the snippet below.

 def chart(request):

    dataSource = {}
    dataSource['chart'] = {
        "caption": "Top 10 Most Populous Countries",
        "showValues": "0",
        "theme": "zune"
        }


    dataSource['data'] = []
    dataSource['linkeddata'] = []

    sbc = MTD.pdobjects.values('Vertical', 'Channel','Brand','Sales_Value')
    sbc_df = sbc.to_dataframe().reset_index(drop=True)#Trying to use filtered model for dataframe
    sbc_df['Sales_Value']=sbc_df['Sales_Value'].astype(float)
    chn_gb=sbc_df.groupby('Channel')['Sales_Value'].sum().reset_index()
    channel=list(chn_gb['Channel'])
    channel_val=list(chn_gb['Sales_Value'])
    sbc_gb=pandas.pivot_table(sbc_df,index=['Vertical','Channel'],values=['Sales_Value'],aggfunc='sum').reset_index()
    brd_gb=pandas.pivot_table(sbc_df,index=['Vertical','Channel','Brand'],values=['Sales_Value'],aggfunc='sum').reset_index()
    for i in range(len(channel)):
      data = {}
      data['label'] = channel[i]
      data['value'] = channel_val[i]

      data['link'] = 'newchart-json-'+ channel[i]
      dataSource['data'].append(data)


      linkData2 = {}

      linkData2['id'] = channel[i]
      linkedchart2 = {}
      linkedchart2['chart'] = {
        "caption" : "Top 10 Most Populous Cities - " + channel[i] ,
        "showValues": "0",
        "theme": "fusion",
        }

      linkedchart2['data'] = []

      sbc_filtered=sbc_gb[sbc_gb.Channel == channel[i]]
      vertical_list=list(sbc_filtered['Vertical'])
      vertical_val=list(sbc_filtered['Sales_Value'])
      for k in range(len(sbc_filtered)):
          arrDara2 = {}
          arrDara2['label'] = vertical_list[k]
          arrDara2['value'] = vertical_val[k]
          arrDara2['link'] = 'newchart-json-'+ vertical_list[k]
          linkedchart2['data'].append(arrDara2)

          linkData1 = {}
          # Inititate the linkData for cities drilldown
          linkData1['id'] = vertical_list[k]
          linkedchart1 = {}
          linkedchart1['chart'] = {
            "caption" : "Top 10 Most Populous Cities - " + vertical_list[k] ,
            "showValues": "0",
            "theme": "fusion",
            }

          linkedchart1['data'] = []

          brd_filtered=brd_gb[(brd_gb.Channel == channel[i]) & (brd_gb.Vertical== vertical_list[k])]
          brd_list=list(brd_filtered['Brand'])
          brd_val=list(brd_filtered['Sales_Value'])
          for j in range(len(brd_filtered)):
              arrDara1 = {}
              arrDara1['label'] = brd_list[j]
              arrDara1['value'] = brd_val[j]
              linkedchart1['data'].append(arrDara1)
          linkData1['linkedchart'] = linkedchart1
          dataSource['linkeddata'].append(linkData1)

      linkData2['linkedchart'] = linkedchart2
      dataSource['linkeddata'].append(linkData2)

      print(dataSource)

    column2D = FusionCharts("column2D", "ex1" , "700", "400", "chart-1", "json", dataSource)
    return render(request, 'table.html',{'output':column2D.render()})

Kindly help me to achieve the successive drilldown correctly.

Thanks


回答1:


In order to change the chart type for the child chart you need to use configureLink API method to set the child chart type, you can also set different chart at a different level, provided the datastructure for each chart is correct, here is how you can do

myChart.configureLink([
    { type: 'bar2d' },
    { type: 'line' },
    { type: 'pie2d' }
]);

Here is a demo - http://jsfiddle.net/x0c2wo7k/

Please note the above sample is using plain javascript



来源:https://stackoverflow.com/questions/55651080/problem-in-rendering-multiple-drilldown-in-fusioncharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!