2009-04-28 8 views
2

J'ai un graphique créé dynamiquement et j'ai besoin d'ajouter un axe horizontal et vertical dans un script. Je ne peux pas mettre le graphique en MXML car je modifie dynamiquement le type de graphique, en supprimant et en créant un nouveau graphique. Par conséquent, la variable que j'utilise pour créer le graphique, une instance de chartBase, ne possède ni horizontalAxis ni verticalAxis. Comment puis-je les attribuer s'ils n'existent pas? Dois-je utiliser un type différent? Les graphiques que je veux utiliser sont ligne, barre et HLOC et/ou chandelier.Flex: comment ajouter des axes horizontaux à un graphique?

Répondre

1

Je pense que vous obtiendrez de meilleurs résultats en instanciant votre graphique comme un type approprié.

Par exemple, dans un composant que j'ai une configuration LineChart squelette dans le MXML ...

<mx:LineChart id="lineChart" dataProvider="{chartData}" dataTipFunction="dataTipFunction" 
    width="100%" 
    height="100%" 
    showDataTips="true" 
    /> 

... mais vous pouvez créer comme une variable et l'ajouter au conteneur. Ensuite, pour l'axe I déterminent le type que je veux et créer et d'appliquer eux, voici un code que j'utilise pour l'axe horizontal ...

// Setup new horizontal axis. 
switch (hAxisFieldsComboBox.selectedItem.dataType) 
{ 
    case "Date": 
     var hDtAxis:DateTimeAxis = new DateTimeAxis(); 
     hDtAxis.title = hAxisFieldsComboBox.selectedItem.label; 
     hDtAxis.dataUnits = "days"; 
     hDtAxis.dataInterval = 1; 
     hDtAxis.parseFunction = dateParser; 
     lineChart.horizontalAxis = hDtAxis; 
     break; 
    case "Time": 
     var hTAxis:DateTimeAxis = new DateTimeAxis(); 
     hTAxis.title = hAxisFieldsComboBox.selectedItem.label; 
     hTAxis.dataInterval = 1; 
     hTAxis.parseFunction = timeParser; 
     lineChart.horizontalAxis = hTAxis; 
     break; 
    case "Number": 
     var hLAxis:LinearAxis = new LinearAxis(); 
     hLAxis.title = hAxisFieldsComboBox.selectedItem.label; 
     hLAxis.interval = 1; 
     hLAxis.minimum = 0; 
     lineChart.horizontalAxis = hLAxis; 
     break; 
    default: 
     var hCatAxis:CategoryAxis = new CategoryAxis(); 
     hCatAxis.title = hAxisFieldsComboBox.selectedItem.label; 
     hCatAxis.dataProvider = schemaUtil.aggregateAndSortCasesAC(chartData, vAxisFieldsComboBox.selectedItem.data, [hAxisFieldsComboBox.selectedItem.data]); 
     hCatAxis.categoryField = hAxisFieldsComboBox.selectedItem.data; 
     lineChart.horizontalAxis = hCatAxis; 
} 

espoir qui aide.

Questions connexes