增加Serie的barType参数,可配置斑马柱状图

This commit is contained in:
monitor1394
2019-10-18 07:41:23 +08:00
parent 1f1d7b0f64
commit b1f5735d45
5 changed files with 26044 additions and 21329 deletions

View File

@@ -129,7 +129,7 @@ namespace XCharts
/// <summary>
/// 斑马柱形图
/// </summary>
ZebraLine,
Zebra,
/// <summary>
/// 胶囊柱形图
/// </summary>
@@ -193,6 +193,9 @@ namespace XCharts
[SerializeField] private float m_BarWidth = 0.6f;
[SerializeField] private float m_BarGap = 0.3f; // 30%
[SerializeField] private float m_BarCategoryGap = 0.2f; // 20%
[SerializeField] private float m_BarZebraWidth = 4f;
[SerializeField] private float m_BarZebraGap = 2f;
[SerializeField] private bool m_ClickOffset = true;
[SerializeField] private RoseType m_RoseType = RoseType.None;
@@ -320,7 +323,7 @@ namespace XCharts
/// </summary>
public BarType barType { get { return m_BarType; } set { m_BarType = value; } }
/// <summary>
/// 柱形图是否为百分比堆积。
/// 柱形图是否为百分比堆积。相同stack的serie只要有一个barPercentStack为true则就显示成百分比堆叠柱状图。
/// </summary>
public bool barPercentStack { get { return m_BarPercentStack; } set { m_BarPercentStack = value; } }
/// <summary>
@@ -349,6 +352,15 @@ namespace XCharts
/// 在同一坐标系上,此属性会被多个 'bar' 系列共享。此属性应设置于此坐标系中最后一个 'bar' 系列上才会生效,并且是对此坐标系中所有 'bar' 系列生效。
/// </summary>
public float barCategoryGap { get { return m_BarCategoryGap; } set { m_BarCategoryGap = value; } }
/// <summary>
/// 斑马线的粗细。
/// </summary>
public float barZebraWidth { get { return m_BarZebraWidth; } set { m_BarZebraWidth = value; } }
/// <summary>
/// 斑马线的间距。
/// </summary>
public float barZebraGap { get { return m_BarZebraGap; } set { m_BarZebraGap = value; } }
/// <summary>
/// Whether offset when mouse click pie chart item.
/// 鼠标点击时是否开启偏移一般用在PieChart图表中。

View File

@@ -52,7 +52,7 @@ namespace XCharts
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = value / valueTotal * coordinateWidth;
barHig = value / valueTotal * coordinateWidth;
seriesHig[i] += barHig;
}
else
@@ -77,7 +77,16 @@ namespace XCharts
{
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
if (serie.barType == BarType.Zebra)
{
p1 = (p4 + p1) / 2;
p2 = (p2 + p3) / 2;
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
}
else
{
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
}
}
}
if (!m_Series.IsStack(serie.stack, SerieType.Bar))
@@ -151,7 +160,7 @@ namespace XCharts
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = value / valueTotal * coordinateHeight;
barHig = value / valueTotal * coordinateHeight;
seriesHig[i] += barHig;
}
else
@@ -177,7 +186,16 @@ namespace XCharts
{
Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
if (serie.barType == BarType.Zebra)
{
p1 = (p4 + p1) / 2;
p2 = (p2 + p3) / 2;
ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
}
else
{
ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
}
}
}
if (!m_Series.IsStack(serie.stack, SerieType.Bar))

View File

@@ -139,6 +139,12 @@ namespace XCharts
DrawLine(vh, sp, p2, size, color);
}
public static void DrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size,
float zebraWidth, float zebraGap, Color32 color)
{
DrawDotLine(vh, p1, p2, size, color, zebraWidth, zebraGap);
}
public static void DrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
bool vertical = true)
{