增加LineChart的Label配置

This commit is contained in:
monitor1394
2019-08-16 00:13:01 +08:00
parent 3e506f9576
commit b464f5b25f
9 changed files with 21259 additions and 8069 deletions

View File

@@ -295,21 +295,32 @@ namespace XCharts
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
if (serie.type != SerieType.Pie) continue;
if (serie.type != SerieType.Pie && serie.type != SerieType.Line) continue;
if (serie.type != SerieType.Pie && !serie.label.show) continue;
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
var textName = s_SerieLabelObjectName + "_" + i + "_" + j + "_" + serieData.name;
var color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
(Color)m_ThemeInfo.GetColor(count++);
var anchorMin = new Vector2(0.5f, 0.5f);
var anchorMax = new Vector2(0.5f, 0.5f);
var pivot = new Vector2(0.5f, 0.5f);
serieData.label = ChartHelper.AddTextObject(textName, labelObject.transform,
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot,
new Vector2(50, serie.label.fontSize), serie.label.fontSize);
serieData.label.text = serieData.name;
ChartHelper.SetActive(serieData.label.gameObject, false);
var color = Color.grey;
if (serie.type == SerieType.Pie)
{
color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
(Color)m_ThemeInfo.GetColor(count);
}
else
{
color = serie.label.color != Color.clear ? serie.label.color :
(Color)m_ThemeInfo.GetColor(i);
}
var backgroundColor = serie.label.backgroundColor;
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font, color, backgroundColor,
serie.label.fontSize, serie.label.fontStyle);
serieData.label = labelObj.GetComponentInChildren<Text>();
serieData.labelImage = labelObj.GetComponent<Image>();
serieData.labelRect = labelObj.GetComponent<RectTransform>();
serieData.SetLabelActive(false);
serieData.SetLabelText(serieData.name);
count++;
}
}
}

View File

@@ -342,6 +342,8 @@ namespace XCharts
private void InitYAxis(int yAxisIndex, YAxis yAxis)
{
yAxis.minValue = 0;
yAxis.maxValue = 100;
yAxis.axisLabelTextList.Clear();
float labelWidth = yAxis.GetScaleWidth(coordinateHig, m_DataZoom);
string objName = yAxisIndex > 0 ? s_DefaultAxisY + "2" : s_DefaultAxisY;
@@ -641,10 +643,7 @@ namespace XCharts
private void UpdateAxisMinMaxValue(int axisIndex, Axis axis)
{
axis.minValue = 0;
axis.maxValue = 0;
if (axis.IsCategory()) return;
int tempMinValue = 0;
int tempMaxValue = 100;
if (m_XAxises[axisIndex].IsValue() && m_YAxises[axisIndex].IsValue())
@@ -663,7 +662,7 @@ namespace XCharts
m_Series.GetYMinMaxValue(m_DataZoom, axisIndex, out tempMinValue, out tempMaxValue);
}
axis.AdjustMinMaxValue(ref tempMinValue, ref tempMaxValue);
if (tempMinValue != axis.minValue || tempMaxValue != axis.maxValue)
{
axis.minValue = tempMinValue;

View File

@@ -48,6 +48,8 @@ namespace XCharts
/// 该数据项的文本标签。
/// </summary>
public Text label { get; set; }
public RectTransform labelRect { get; set; }
public Image labelImage { get; set; }
/// <summary>
/// the maxinum value.
/// 最大值。
@@ -64,5 +66,31 @@ namespace XCharts
if (index >= 0 && index < m_Data.Count) return m_Data[index];
else return 0;
}
public void SetLabelActive(bool active)
{
if (labelImage)
{
ChartHelper.SetActive(labelImage.gameObject, active);
}
}
public void SetLabelText(string text)
{
if (label)
{
label.text = text;
labelRect.sizeDelta = new Vector2(label.preferredWidth + 4,
label.preferredHeight + 4);
}
}
public void SetLabelPosition(Vector3 position)
{
if (labelImage)
{
labelImage.transform.localPosition = position;
}
}
}
}

View File

@@ -56,6 +56,7 @@ namespace XCharts
[SerializeField] private float m_Distance;
[SerializeField] private float m_Rotate;
[SerializeField] private Color m_Color;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
[SerializeField] private bool m_Line = true;
@@ -82,6 +83,7 @@ namespace XCharts
/// 自定义文字颜色,默认和系列的颜色一致。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
/// <summary>
/// Rotate label.
/// 标签旋转。