1- namespace Highcharts
1+ using System . Linq ;
2+
3+ namespace Highcharts
24{
35 using System ;
46 using System . Collections . Generic ;
@@ -135,16 +137,18 @@ public void RecalcCategories()
135137 cachedCategoriesStep = cachedPlotWidth ;
136138 else
137139 cachedCategoriesStep = ( float ) cachedPlotWidth / ( cachedCategories . Length - 1 ) ;
138-
140+
139141 if ( cachedCategoriesStep < categoriesMinStep )
140142 {
141143 cachedCategoriesStep = categoriesMinStep ;
142144
143145 // Filter categories.
144146 cachedCategoriesFiltered = new List < string > ( ) ;
145147 for ( float i = 0 ; i < cachedCategories . Length ; i += skipFactor )
146- cachedCategoriesFiltered . Add ( cachedCategories [ ( int ) i ] ) ;
148+ cachedCategoriesFiltered . Add ( cachedCategories [ ( int ) i ] ) ;
147149 }
150+ else
151+ cachedCategoriesFiltered = cachedCategories . ToList ( ) ;
148152 }
149153 }
150154 }
@@ -321,6 +325,7 @@ private void DrawSeries(Graphics g, Series s)
321325 {
322326 double currentValue = s . data [ ( int ) i ] ;
323327
328+ bool last = i + pointInterval >= sdataCount ;
324329 float currentValueYCoef = ( float ) ( ( currentValue - cachedPlotMin ) / valueRange ) ;
325330 float currentValueX = cachedPlotLeft + xStep * categoriesIndex ;
326331 float currentValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * currentValueYCoef ;
@@ -333,7 +338,7 @@ private void DrawSeries(Graphics g, Series s)
333338 {
334339 if ( locationX + currentValueX < - uwfOffset . X ) // Left side.
335340 clipHorizontal = true ;
336- if ( locationX + currentValueX + xStep + uwfOffset . X > parentWidth ) // Right side.
341+ if ( locationX + currentValueX + uwfOffset . X > parentWidth ) // Right side.
337342 clipHorizontal = true ;
338343 }
339344
@@ -344,8 +349,6 @@ private void DrawSeries(Graphics g, Series s)
344349 {
345350 if ( i > 0 )
346351 {
347- bool last = i + pointInterval >= sdataCount ;
348-
349352 float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
350353 float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
351354 float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
@@ -366,8 +369,6 @@ private void DrawSeries(Graphics g, Series s)
366369 float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
367370 float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
368371
369- bool last = i + pointInterval >= sdataCount ;
370-
371372 if ( s . linearGradient == false )
372373 {
373374 g . uwfFillRectangle ( areaColor , prevValueX , prevValueY , currentValueX - prevValueX ,
@@ -408,10 +409,13 @@ private void DrawSeries(Graphics g, Series s)
408409 break ;
409410 case SeriesTypes . line :
410411 {
411- float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
412- float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
413- float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
414- g . DrawLine ( s . pen , prevValueX , prevValueY , currentValueX + 1 , currentValueY ) ;
412+ if ( i > 0 )
413+ {
414+ float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
415+ float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
416+ float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
417+ g . DrawLine ( s . pen , prevValueX , prevValueY , currentValueX + 1 , currentValueY ) ;
418+ }
415419 }
416420 break ;
417421 case SeriesTypes . lineSolid :
@@ -723,17 +727,12 @@ private double ValueAtX(Series s, int x)
723727 var sdataCount = s . data . Count ;
724728 if ( sdataCount == 0 ) return 0 ;
725729
726- float pointInterval = s . pointInterval ;
727- float xStep = cachedCategoriesStep ;
728- if ( sdataCount > 1 )
729- xStep = ( float ) cachedPlotWidth / ( sdataCount - 1 ) ;
730- xStep *= pointInterval ;
731-
732- var categoriesIndex = ( int ) ( ( x - cachedPlotLeft ) / xStep ) ;
733- if ( categoriesIndex < 0 || categoriesIndex >= sdataCount )
730+ var xCoef = ( float ) ( x - cachedPlotLeft ) / cachedPlotWidth ;
731+ var dataIndex = ( int ) ( xCoef * sdataCount ) ;
732+ if ( dataIndex > sdataCount )
734733 return 0 ;
735734
736- return s . data [ categoriesIndex ] ;
735+ return s . data [ dataIndex ] ;
737736 }
738737 }
739738}
0 commit comments