@@ -660,10 +660,11 @@ private static void MoveCursor(Chart chart, CursorDirection dir)
660
660
else if ( dir == CursorDirection . Right ) ptrCursor . DataIndex ++ ;
661
661
Debug . WriteLine ( "New DataIndex = " + ptrCursor . DataIndex . ToString ( ) ) ;
662
662
663
- if ( ptrCursor . DataIndex < 0 ) ptrCursor . DataIndex = 0 ;
663
+ if ( ptrCursor . DataIndex <= 0 ) ptrCursor . DataIndex = 0 ;
664
664
else if ( ptrCursor . DataIndex >= ptrSeries . Points . Count ( ) ) ptrCursor . DataIndex = ptrSeries . Points . Count ( ) - 1 ;
665
665
666
666
DataPoint [ ] datas = ptrSeries . Points . OrderBy ( x => x . XValue ) . ToArray ( ) ;
667
+ if ( datas . Length == 0 ) return ; //Skip the rest of the code when series have no valid data.
667
668
668
669
ptrCursor . X = datas [ ptrCursor . DataIndex ] . XValue ;
669
670
ptrCursor . Y = datas [ ptrCursor . DataIndex ] . YValues . First ( ) ;
@@ -706,14 +707,40 @@ private static void MoveCursor(this Chart ptrChart, double newX, double newY)
706
707
DrawHorizontalLine ( ptrChart , YStart , cursorColor , ptrChartArea . Name + "Cursor_1Y" , lineWidth , cursorDashStyle , ptrChartArea , ptrSeries . YAxisType ) ;
707
708
ptrChartData . Cursor1 . X = XStart ;
708
709
ptrChartData . Cursor1 . Y = YStart ;
709
- ptrChartData . Cursor1 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
710
- ptrChartData . Cursor1 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
710
+ ptrChartData . Cursor1 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType ,
711
+ ( ptrSeries . XAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatX1 : ptrChartData . Option . CursorLabelStringFormatX2 ) ) ;
712
+ ptrChartData . Cursor1 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType ,
713
+ ( ptrSeries . YAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatY1 : ptrChartData . Option . CursorLabelStringFormatY2 ) ) ;
711
714
ptrChartData . Cursor1 . ChartArea = ptrChartArea ;
712
715
713
716
if ( ptrChartData . Option . ShowCursorValue )
714
717
{
718
+ string xPrefix , xPostfix , yPrefix , yPostfix ;
719
+ if ( ptrSeries . XAxisType == AxisType . Primary )
720
+ {
721
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX1 ;
722
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX1 ;
723
+ }
724
+ else
725
+ {
726
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX2 ;
727
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX2 ;
728
+ }
729
+
730
+ if ( ptrSeries . YAxisType == AxisType . Primary )
731
+ {
732
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY1 ;
733
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY1 ;
734
+ }
735
+ else
736
+ {
737
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY2 ;
738
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY2 ;
739
+ }
740
+
715
741
//Add Cursor Value : X, Y
716
- string cursorValue = ptrChartData . Cursor1 . XFormattedString + "," + ptrChartData . Cursor1 . YFormattedString ;
742
+ string cursorValue = xPrefix + ptrChartData . Cursor1 . XFormattedString + xPostfix + "," +
743
+ yPrefix + ptrChartData . Cursor1 . YFormattedString + yPostfix ;
717
744
AddText ( ptrChart , cursorValue , XStart , YStart , cursorColor , ptrChartArea . Name + "cursor1_Label" , TextStyle . Default , ptrChartArea , ptrSeries . XAxisType , ptrSeries . YAxisType ) ;
718
745
}
719
746
ptrChartData . PositionChangedCallback ? . Invoke ( ptrChart , ptrChartData . Cursor1 . Clone ( ) as ChartCursor ) ;
@@ -746,14 +773,41 @@ private static void MoveCursor(this Chart ptrChart, double newX, double newY)
746
773
DrawHorizontalLine ( ptrChart , YStart , cursorColor , ptrChartArea . Name + "Cursor_2Y" , lineWidth , cursorDashStyle , ptrChartArea , ptrSeries . YAxisType ) ;
747
774
ptrChartData . Cursor2 . X = XStart ;
748
775
ptrChartData . Cursor2 . Y = YStart ;
749
- ptrChartData . Cursor2 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
750
- ptrChartData . Cursor2 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
776
+ ptrChartData . Cursor2 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType ,
777
+ ( ptrSeries . XAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatX1 : ptrChartData . Option . CursorLabelStringFormatX2 ) ) ;
778
+ ptrChartData . Cursor2 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType ,
779
+ ( ptrSeries . YAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatY1 : ptrChartData . Option . CursorLabelStringFormatY2 ) ) ;
751
780
ptrChartData . Cursor2 . ChartArea = ptrChartArea ;
752
781
782
+
753
783
if ( ptrChartData . Option . ShowCursorValue )
754
784
{
785
+ string xPrefix , xPostfix , yPrefix , yPostfix ;
786
+ if ( ptrSeries . XAxisType == AxisType . Primary )
787
+ {
788
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX1 ;
789
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX1 ;
790
+ }
791
+ else
792
+ {
793
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX2 ;
794
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX2 ;
795
+ }
796
+
797
+ if ( ptrSeries . YAxisType == AxisType . Primary )
798
+ {
799
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY1 ;
800
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY1 ;
801
+ }
802
+ else
803
+ {
804
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY2 ;
805
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY2 ;
806
+ }
807
+
755
808
//Add Cursor Value : X, Y
756
- string cursorValue = ptrChartData . Cursor2 . XFormattedString + "," + ptrChartData . Cursor2 . YFormattedString ;
809
+ string cursorValue = xPrefix + ptrChartData . Cursor2 . XFormattedString + xPostfix + "," +
810
+ yPrefix + ptrChartData . Cursor2 . YFormattedString + yPostfix ;
757
811
AddText ( ptrChart , cursorValue , XStart , YStart , cursorColor , ptrChartArea . Name + "cursor2_Label" , TextStyle . Default , ptrChartArea , ptrSeries . XAxisType , ptrSeries . YAxisType ) ;
758
812
}
759
813
ptrChartData . PositionChangedCallback ? . Invoke ( ptrChart , ptrChartData . Cursor2 . Clone ( ) as ChartCursor ) ;
@@ -936,20 +990,47 @@ private static void ChartControl_MouseDown(object sender, MouseEventArgs e)
936
990
ptrChartData . Cursor1 . X = XStart ;
937
991
ptrChartData . Cursor1 . Y = YStart ;
938
992
ptrChartData . Cursor1 . DataIndex = dataIndex ;
939
- ptrChartData . Cursor1 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
940
- ptrChartData . Cursor1 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
993
+ ptrChartData . Cursor1 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType ,
994
+ ( ptrSeries . XAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatX1 : ptrChartData . Option . CursorLabelStringFormatX2 ) ) ;
995
+ ptrChartData . Cursor1 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType ,
996
+ ( ptrSeries . YAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatY1 : ptrChartData . Option . CursorLabelStringFormatY2 ) ) ;
941
997
ptrChartData . Cursor1 . ChartArea = ptrChartArea ;
942
998
943
999
if ( ptrChartData . Option . ShowCursorValue )
944
1000
{
1001
+ string xPrefix , xPostfix , yPrefix , yPostfix ;
1002
+ if ( ptrSeries . XAxisType == AxisType . Primary )
1003
+ {
1004
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX1 ;
1005
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX1 ;
1006
+ }
1007
+ else
1008
+ {
1009
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX2 ;
1010
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX2 ;
1011
+ }
1012
+
1013
+ if ( ptrSeries . YAxisType == AxisType . Primary )
1014
+ {
1015
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY1 ;
1016
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY1 ;
1017
+ }
1018
+ else
1019
+ {
1020
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY2 ;
1021
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY2 ;
1022
+ }
1023
+
945
1024
//Add Cursor Value : X, Y
946
- string cursorValue = ptrChartData . Cursor1 . XFormattedString + "," + ptrChartData . Cursor1 . YFormattedString ;
1025
+ string cursorValue = xPrefix + ptrChartData . Cursor1 . XFormattedString + xPostfix + "," +
1026
+ yPrefix + ptrChartData . Cursor1 . YFormattedString + yPostfix ;
947
1027
AddText ( ptrChart , cursorValue , XStart , YStart , cursorColor , ptrChartArea . Name + "cursor1_Label" , TextStyle . Default , ptrChartArea , ptrSeries . XAxisType , ptrSeries . YAxisType ) ;
948
1028
}
949
1029
950
1030
ptrChartData . PositionChangedCallback ? . Invoke ( ptrChart , ptrChartData . Cursor1 . Clone ( ) as ChartCursor ) ;
951
1031
}
952
1032
}
1033
+ ptrChart . Focus ( ) ;
953
1034
}
954
1035
else if ( ptrChartData . ToolState == MSChartExtensionToolState . Select2 )
955
1036
{
@@ -980,20 +1061,47 @@ private static void ChartControl_MouseDown(object sender, MouseEventArgs e)
980
1061
ptrChartData . Cursor2 . X = XStart ;
981
1062
ptrChartData . Cursor2 . Y = YStart ;
982
1063
ptrChartData . Cursor2 . DataIndex = dataIndex ;
983
- ptrChartData . Cursor2 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
984
- ptrChartData . Cursor2 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType , ptrChartData . Option . CursorLabelStringFormat ) ;
1064
+ ptrChartData . Cursor2 . XFormattedString = FormatCursorValue ( XStart , ptrSeries . XValueType ,
1065
+ ( ptrSeries . XAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatX1 : ptrChartData . Option . CursorLabelStringFormatX2 ) ) ;
1066
+ ptrChartData . Cursor2 . YFormattedString = FormatCursorValue ( YStart , ptrSeries . YValueType ,
1067
+ ( ptrSeries . YAxisType == AxisType . Primary ? ptrChartData . Option . CursorLabelStringFormatY1 : ptrChartData . Option . CursorLabelStringFormatY2 ) ) ;
985
1068
ptrChartData . Cursor2 . ChartArea = ptrChartArea ;
986
1069
987
1070
if ( ptrChartData . Option . ShowCursorValue )
988
1071
{
1072
+ string xPrefix , xPostfix , yPrefix , yPostfix ;
1073
+ if ( ptrSeries . XAxisType == AxisType . Primary )
1074
+ {
1075
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX1 ;
1076
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX1 ;
1077
+ }
1078
+ else
1079
+ {
1080
+ xPrefix = ptrChartData . Option . CursorLabelPrefixX2 ;
1081
+ xPostfix = ptrChartData . Option . CursorLabelPostfixX2 ;
1082
+ }
1083
+
1084
+ if ( ptrSeries . YAxisType == AxisType . Primary )
1085
+ {
1086
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY1 ;
1087
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY1 ;
1088
+ }
1089
+ else
1090
+ {
1091
+ yPrefix = ptrChartData . Option . CursorLabelPrefixY2 ;
1092
+ yPostfix = ptrChartData . Option . CursorLabelPostfixY2 ;
1093
+ }
1094
+
989
1095
//Add Cursor Value : X, Y
990
- string cursorValue = ptrChartData . Cursor2 . XFormattedString + "," + ptrChartData . Cursor2 . YFormattedString ;
1096
+ string cursorValue = xPrefix + ptrChartData . Cursor2 . XFormattedString + xPostfix + "," +
1097
+ yPrefix + ptrChartData . Cursor2 . YFormattedString + yPostfix ;
991
1098
AddText ( ptrChart , cursorValue , XStart , YStart , cursorColor , ptrChartArea . Name + "cursor2_Label" , TextStyle . Default , ptrChartArea , ptrSeries . XAxisType , ptrSeries . YAxisType ) ;
992
1099
}
993
1100
994
1101
ptrChartData . PositionChangedCallback ? . Invoke ( ptrChart , ptrChartData . Cursor2 . Clone ( ) as ChartCursor ) ;
995
1102
}
996
1103
}
1104
+ ptrChart . Focus ( ) ;
997
1105
}
998
1106
}
999
1107
@@ -1082,8 +1190,8 @@ private static void ChartControl_MouseMove(object sender, MouseEventArgs e)
1082
1190
X = selX ,
1083
1191
Y = selY ,
1084
1192
ChartArea = ptrChartArea ,
1085
- XFormattedString = FormatCursorValue ( selX , xValueType , ptrChartData . Option . CursorLabelStringFormat ) ,
1086
- YFormattedString = FormatCursorValue ( selY , yValueType , ptrChartData . Option . CursorLabelStringFormat )
1193
+ XFormattedString = FormatCursorValue ( selX , xValueType , ptrChartData . Option . CursorLabelStringFormatX1 ) ,
1194
+ YFormattedString = FormatCursorValue ( selY , yValueType , ptrChartData . Option . CursorLabelStringFormatY1 )
1087
1195
} ) ;
1088
1196
}
1089
1197
catch ( Exception )
0 commit comments