* UILineChart:可自定义背景色
This commit is contained in:
parent
2ef88246cd
commit
e9946fd631
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
SunnyUI.Demo/Charts/FBarChart.Designer.cs
generated
1
SunnyUI.Demo/Charts/FBarChart.Designer.cs
generated
@ -117,6 +117,7 @@ namespace Sunny.UI.Demo
|
||||
this.BarChart.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
this.BarChart.Name = "BarChart";
|
||||
this.BarChart.Size = new System.Drawing.Size(670, 400);
|
||||
this.BarChart.Style = Sunny.UI.UIStyle.Custom;
|
||||
this.BarChart.TabIndex = 29;
|
||||
this.BarChart.Text = "uiBarChart1";
|
||||
//
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Sunny.UI.Demo
|
||||
{
|
||||
@ -62,9 +63,13 @@ namespace Sunny.UI.Demo
|
||||
|
||||
option.XAxis.Name = "日期";
|
||||
option.YAxis.Name = "数值";
|
||||
option.YAxis.AxisLabel.DecimalCount = 1;
|
||||
option.YAxis.AxisLabel.AutoFormat = false;
|
||||
|
||||
//option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
||||
//option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
||||
option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
||||
|
||||
option.ToolTip.AxisPointer.Type = UIAxisPointerType.Shadow;
|
||||
|
||||
BarChart.SetOption(option);
|
||||
|
||||
|
@ -266,7 +266,7 @@ namespace Sunny.UI.Demo
|
||||
//
|
||||
this.AllowShowTitle = true;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(776, 543);
|
||||
this.Controls.Add(this.uiLabel2);
|
||||
this.Controls.Add(this.uiPanel11);
|
@ -335,10 +335,10 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="FColorful.cs">
|
||||
<Compile Include="Forms\FColorful.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FColorful.Designer.cs">
|
||||
<Compile Include="Forms\FColorful.Designer.cs">
|
||||
<DependentUpon>FColorful.cs</DependentUpon>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Charts\FBarChartEx.resx">
|
||||
@ -489,7 +489,7 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="FColorful.resx">
|
||||
<EmbeddedResource Include="Forms\FColorful.resx">
|
||||
<DependentUpon>FColorful.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="..\.editorconfig">
|
||||
|
@ -445,10 +445,10 @@ namespace Sunny.UI
|
||||
|
||||
protected virtual void DrawAxis(Graphics g)
|
||||
{
|
||||
if (YAxisStart >= 0) g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
||||
if (YAxisEnd <= 0) g.DrawLine(ChartStyle.ForeColor, new Point(DrawOrigin.X, Option.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, Option.Grid.Top));
|
||||
if (YAxisStart >= 0) g.DrawLine(ForeColor, DrawOrigin, new Point(DrawOrigin.X + DrawSize.Width, DrawOrigin.Y));
|
||||
if (YAxisEnd <= 0) g.DrawLine(ForeColor, new Point(DrawOrigin.X, Option.Grid.Top), new Point(DrawOrigin.X + DrawSize.Width, Option.Grid.Top));
|
||||
|
||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
|
||||
g.DrawLine(ForeColor, DrawOrigin, new Point(DrawOrigin.X, DrawOrigin.Y - DrawSize.Height));
|
||||
|
||||
if (Option.XAxis.AxisTick.Show)
|
||||
{
|
||||
@ -459,7 +459,7 @@ namespace Sunny.UI
|
||||
start = DrawOrigin.X + DrawBarWidth / 2.0f;
|
||||
for (int i = 0; i < Option.XAxis.Data.Count; i++)
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
g.DrawLine(ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
start += DrawBarWidth;
|
||||
}
|
||||
}
|
||||
@ -480,7 +480,7 @@ namespace Sunny.UI
|
||||
start = DrawOrigin.X;
|
||||
for (int i = 0; i <= Option.XAxis.Data.Count; i++)
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
g.DrawLine(ForeColor, start, DrawOrigin.Y, start, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
start += DrawBarWidth;
|
||||
}
|
||||
}
|
||||
@ -493,12 +493,12 @@ namespace Sunny.UI
|
||||
foreach (var data in Option.XAxis.Data)
|
||||
{
|
||||
SizeF sf = g.MeasureString(data, SubFont);
|
||||
g.DrawString(data, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
g.DrawString(data, SubFont, ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
start += DrawBarWidth;
|
||||
}
|
||||
|
||||
SizeF sfname = g.MeasureString(Option.XAxis.Name, SubFont);
|
||||
g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfname.Height);
|
||||
g.DrawString(Option.XAxis.Name, SubFont, ForeColor, DrawOrigin.X + (DrawSize.Width - sfname.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfname.Height);
|
||||
}
|
||||
|
||||
if (Option.YAxis.AxisTick.Show)
|
||||
@ -507,11 +507,11 @@ namespace Sunny.UI
|
||||
float DrawBarHeight = DrawSize.Height * 1.0f / (YAxisEnd - YAxisStart);
|
||||
for (int i = YAxisStart; i <= YAxisEnd; i++)
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, DrawOrigin.X - Option.YAxis.AxisTick.Length, start);
|
||||
g.DrawLine(ForeColor, DrawOrigin.X, start, DrawOrigin.X - Option.YAxis.AxisTick.Length, start);
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
using (Pen pn = new Pen(ChartStyle.ForeColor))
|
||||
using (Pen pn = new Pen(ForeColor))
|
||||
{
|
||||
pn.DashStyle = DashStyle.Dash;
|
||||
pn.DashPattern = new float[] { 3, 3 };
|
||||
@ -520,12 +520,12 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, start, Width - Option.Grid.Right, start);
|
||||
g.DrawLine(ForeColor, DrawOrigin.X, start, Width - Option.Grid.Right, start);
|
||||
|
||||
float lineStart = DrawOrigin.X;
|
||||
for (int j = 0; j <= Option.XAxis.Data.Count; j++)
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, lineStart, start, lineStart, start + Option.XAxis.AxisTick.Length);
|
||||
g.DrawLine(ForeColor, lineStart, start, lineStart, start + Option.XAxis.AxisTick.Length);
|
||||
lineStart += DrawBarWidth;
|
||||
}
|
||||
}
|
||||
@ -549,14 +549,14 @@ namespace Sunny.UI
|
||||
string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx);
|
||||
SizeF sf = g.MeasureString(label, SubFont);
|
||||
wmax = Math.Max(wmax, sf.Width);
|
||||
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
|
||||
g.DrawString(label, SubFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f);
|
||||
start -= DrawBarHeight;
|
||||
}
|
||||
|
||||
SizeF sfname = g.MeasureString(Option.YAxis.Name, SubFont);
|
||||
int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height);
|
||||
int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2);
|
||||
g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y),
|
||||
g.DrawString(Option.YAxis.Name, SubFont, ForeColor, new Point(x, y),
|
||||
new StringFormat() { Alignment = StringAlignment.Center }, 270);
|
||||
}
|
||||
}
|
||||
@ -569,6 +569,7 @@ namespace Sunny.UI
|
||||
double ymax = YAxisEnd * YAxisInterval;
|
||||
float pos = (float)((line.Value - ymin) * (Height - Option.Grid.Top - Option.Grid.Bottom) / (ymax - ymin));
|
||||
pos = (Height - Option.Grid.Bottom - pos);
|
||||
if (pos <= Option.Grid.Top || pos >= Height - Option.Grid.Bottom) continue;
|
||||
using (Pen pn = new Pen(line.Color, line.Size))
|
||||
{
|
||||
g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos);
|
||||
|
@ -197,11 +197,11 @@ namespace Sunny.UI
|
||||
|
||||
private void DrawAxis(Graphics g)
|
||||
{
|
||||
g.DrawRectangle(ChartStyle.ForeColor, Option.Grid.Left, Option.Grid.Top, DrawSize.Width, DrawSize.Height);
|
||||
g.DrawRectangle(ForeColor, Option.Grid.Left, Option.Grid.Top, DrawSize.Width, DrawSize.Height);
|
||||
float zeroPos = YScale.CalcYPixel(0, DrawOrigin.Y, DrawSize.Height);
|
||||
if (zeroPos > Option.Grid.Top && zeroPos < Height - Option.Grid.Bottom)
|
||||
{
|
||||
g.DrawLine(ChartStyle.ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
|
||||
g.DrawLine(ForeColor, DrawOrigin.X, zeroPos, DrawOrigin.X + DrawSize.Width, zeroPos);
|
||||
}
|
||||
|
||||
if (XScale == null || YScale == null) return;
|
||||
@ -234,13 +234,13 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
SizeF sf = g.MeasureString(label, SubFont);
|
||||
g.DrawString(label, SubFont, ChartStyle.ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
g.DrawString(label, SubFont, ForeColor, x - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length);
|
||||
}
|
||||
|
||||
if (x.Equals(DrawOrigin.X)) continue;
|
||||
if (x.Equals(DrawOrigin.X + DrawSize.Width)) continue;
|
||||
|
||||
using (Pen pn = new Pen(ChartStyle.ForeColor))
|
||||
using (Pen pn = new Pen(ForeColor))
|
||||
{
|
||||
pn.DashStyle = DashStyle.Dash;
|
||||
pn.DashPattern = new float[] { 3, 3 };
|
||||
@ -249,7 +249,7 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
SizeF sfName = g.MeasureString(Option.XAxis.Name, SubFont);
|
||||
g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor,
|
||||
g.DrawString(Option.XAxis.Name, SubFont, ForeColor,
|
||||
DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f,
|
||||
DrawOrigin.Y + Option.XAxis.AxisTick.Length + sfName.Height);
|
||||
}
|
||||
@ -269,13 +269,13 @@ namespace Sunny.UI
|
||||
string label = YLabels[i].ToString(YScale.Format);
|
||||
SizeF sf = g.MeasureString(label, SubFont);
|
||||
widthMax = Math.Max(widthMax, sf.Width);
|
||||
g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
|
||||
g.DrawString(label, SubFont, ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, y - sf.Height / 2.0f);
|
||||
}
|
||||
|
||||
if (y.Equals(DrawOrigin.Y)) continue;
|
||||
if (y.Equals(DrawOrigin.X - DrawSize.Height)) continue;
|
||||
|
||||
using (Pen pn = new Pen(ChartStyle.ForeColor))
|
||||
using (Pen pn = new Pen(ForeColor))
|
||||
{
|
||||
pn.DashStyle = DashStyle.Dash;
|
||||
pn.DashPattern = new float[] { 3, 3 };
|
||||
@ -286,7 +286,7 @@ namespace Sunny.UI
|
||||
SizeF sfName = g.MeasureString(Option.YAxis.Name, SubFont);
|
||||
float xx = DrawOrigin.X - Option.YAxis.AxisTick.Length - widthMax - sfName.Height / 2.0f;
|
||||
float yy = Option.Grid.Top + DrawSize.Height / 2.0f;
|
||||
g.DrawStringRotateAtCenter(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new PointF(xx, yy), 270);
|
||||
g.DrawStringRotateAtCenter(Option.YAxis.Name, SubFont, ForeColor, new PointF(xx, yy), 270);
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,17 +322,17 @@ namespace Sunny.UI
|
||||
|
||||
using (Graphics graphics = bmp.Graphics())
|
||||
{
|
||||
graphics.FillRectangle(ChartStyle.BackColor, 0, 0, Width, Height);
|
||||
graphics.FillRectangle(FillColor, 0, 0, Width, Height);
|
||||
}
|
||||
|
||||
using (Graphics graphics = bmpGreater.Graphics())
|
||||
{
|
||||
graphics.FillRectangle(ChartStyle.BackColor, 0, 0, Width, Height);
|
||||
graphics.FillRectangle(FillColor, 0, 0, Width, Height);
|
||||
}
|
||||
|
||||
using (Graphics graphics = bmpLess.Graphics())
|
||||
{
|
||||
graphics.FillRectangle(ChartStyle.BackColor, 0, 0, Width, Height);
|
||||
graphics.FillRectangle(FillColor, 0, 0, Width, Height);
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
@ -430,7 +430,7 @@ namespace Sunny.UI
|
||||
|
||||
if (series.Symbol != UILinePointSymbol.None)
|
||||
{
|
||||
using (Brush br = new SolidBrush(ChartStyle.BackColor))
|
||||
using (Brush br = new SolidBrush(FillColor))
|
||||
using (Pen pn = new Pen(color, series.SymbolLineWidth))
|
||||
{
|
||||
foreach (var p in series.Points)
|
||||
|
@ -874,6 +874,11 @@ namespace Sunny.UI
|
||||
return node;
|
||||
}
|
||||
|
||||
public TreeNode CreateNode(int symbol, int symbolSize, UIPage page)
|
||||
{
|
||||
return CreateNode(new NavMenuItem(page), symbol, symbolSize);
|
||||
}
|
||||
|
||||
public TreeNode CreateNode(string text, int symbol, int symbolSize, int pageIndex)
|
||||
{
|
||||
return CreateNode(new NavMenuItem(text, pageIndex), symbol, symbolSize);
|
||||
|
@ -392,6 +392,8 @@ namespace Sunny.UI
|
||||
Text = page.Text;
|
||||
PageIndex = page.PageIndex;
|
||||
PageGuid = page.PageGuid;
|
||||
Symbol = page.Symbol;
|
||||
SymbolSize = page.SymbolSize;
|
||||
AlwaysOpen = page.AlwaysOpen;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user