2017-07-18 55 views
1

我在sheild UI中有以下代碼段。jQuery自定義在Sheild UI中的X軸TicksRepeat

<Axes> 
    <shield:ChartAxisY> 
     <Title Text="Portfolio Value($)"></Title> 
    </shield:ChartAxisY> 
    <shield:ChartAxisX TicksRepeat="10" CategoricalValues=""> 
     <Title Text="Portfolio Date"></Title>  
     <AxisTickText></AxisTickText>     
    </shield:ChartAxisX> 
</Axes> 

我想要的是TicksRepeat被定製。例如,我有兩個日期值,from dateto date。如果差值爲一年,TicksRepeat應該是12,即在幾個月內。如果差異是一個月,那麼TicksRepeat應該在幾天內。等等

請問jQuery會訣竅嗎? 我是jQuery的新手。有人可以幫助實現這一目標嗎?

回答

1

您可以使用圖表API使用帶有Javascript的ticksRepeat選項來刷新圖表。只需選擇目標圖表元素即可執行API方法。 以下是實現所需功能的代碼。

var chart = $('#chart').swidget(); // your target sheild chart selector 

var tickRepeat; // to store the tick repeat value 

// Your if condition to check the date difference 
// Based on the diffrence set the value of `tickRepeat` 
if(<your-year-conditions>){ 
tickRepeat = 12; 
}else{ 
tickRepeat = <your-days-value>; // replace with your days diff 
} 

// Call the refresh method on the Chart Object to rerender the chart 
// With your new tickRepeat on X Axis as below. 
chart.refresh({axisX: {ticksRepeat: tickRepeat }}); 

您可以結算詳細圖表API Documentation以及其他可配置選項。

希望這會有所幫助!