저는 WPF 및 C#에서 새로운 기능을 제공하지만이 커뮤니티 덕분에 신속하게 답변을 드리겠습니다. 나는 라이브 차트에서 내 프로젝트에 각도 게이지를 구현하려고 시도했다. 이 예와 같이 고정 된 하나의 바인드 된 값과 나머지 값은 (https://lvcharts.net/App/examples/v1/wpf/Angular%20Gauge) 잘 작동합니다.WPF 게이지의 동적 값
누군가 내 코드를 동적으로 적용 할 수 있도록 도와 줄 수 있습니까? 에서 고정 값을 갖는 대신 FromValue :ToValue : 내 데이터베이스의 값에 바인드하거나 목표에 따라 계산하고 싶습니다. 모든 제안을 환영합니다. 여기
내가 지금까지 가지고 작업 내용은 다음과 같습니다XAML :
<lvc:AngularGauge Value="{Binding Value}" FromValue="0" Grid.Column="1" ToValue="250"
LabelsStep="50" TicksStep="25" Wedge="300"
TicksForeground="White" Foreground="WhiteSmoke"
FontWeight="Bold" FontSize="16"
SectionsInnerRadius=".6" Width="310">
<lvc:AngularGauge.Sections>
<lvc:AngularSection FromValue="0" ToValue="62.5" Fill="#dd5143"/>
<lvc:AngularSection FromValue="62.5" ToValue="125" Fill="#e68523"/>
<lvc:AngularSection FromValue="125" ToValue="187.5" Fill="#edb220"/>
<lvc:AngularSection FromValue="175" ToValue="250" Fill="#7cb82f"/>
</lvc:AngularGauge.Sections>
</lvc:AngularGauge>
C 번호 : 나는 그것을 알고있다 (달성하고 싶지만 작동하지 않습니다 무엇
namespace Car_App
public partial class MainWindow : MetroWindow
{
private double _value;
public MainWindow()
{
InitializeComponent();
string connectionString = "datasource=xx.xx.xxx.xxx;port=xxxx;username=xxxx;password=xxx";
string sMonth = DateTime.Now.ToString("MM");
string sYear = DateTime.Now.ToString("yyyy");
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("Select * from Table.MyTable where MONTH(Date) = @sMonth AND YEAR(Date) = @sYear", connection);
MySqlCommand sCarCT = new MySqlCommand("Select TotalCarCount from Table.CarTotals where sMonth = @sMonth", connection);
MySqlCommand target = new MySqlCommand("Select Target from Table.Targets where Location = 'xxxxx'", connection);
try
{
connection.Open();
cmd.Parameters.Add(new MySqlParameter("sMonth", sMonth));
cmd.Parameters.Add(new MySqlParameter("sYear", sYear));
sCarCT.Parameters.Add(new MySqlParameter("sMonth", sMonth));
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
dtGrid.DataContext = dt;
Value = double.Parse(sCarCT.ExecuteScalar().ToString());
DataContext = this;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}
public double Value
{
get { return _value; }
set
{
_value = value;
}
}
}
일할 기회가 없지만 누군가가 올바르게 다시 쓸 수 있도록 도와 줄 수 있기를 바랍니다.) :
XAML :
이<lvc:AngularGauge Value="{Binding Value}" FromValue="0" Grid.Column="1" ToValue="{Binding ValueT}"
LabelsStep="50" TicksStep="25" Wedge="300"
TicksForeground="White" Foreground="WhiteSmoke"
FontWeight="Bold" FontSize="16"
SectionsInnerRadius=".6" Width="310">
<lvc:AngularGauge.Sections>
<lvc:AngularSection FromValue="0" ToValue="{Binding Value25}" Fill="#dd5143"/>
<lvc:AngularSection FromValue="{Binding Value25}" ToValue="{Binding Value50}" Fill="#e68523"/>
<lvc:AngularSection FromValue="{Binding Value50}" ToValue="{Binding Value75}" Fill="#edb220"/>
<lvc:AngularSection FromValue="{Binding Value75}" ToValue="{Binding ValueT}" Fill="#7cb82f"/>
</lvc:AngularGauge.Sections>
</lvc:AngularGauge>
C 번호 :
namespace Car_App
public partial class MainWindow : MetroWindow
{
private double _value;
public MainWindow()
{
InitializeComponent();
string connectionString = "datasource=xx.xx.xxx.xxx;port=xxxx;username=xxxx;password=xxx";
string sMonth = DateTime.Now.ToString("MM");
string sYear = DateTime.Now.ToString("yyyy");
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("Select * from Table.Car where MONTH(Date) = @sMonth AND YEAR(Date) = @sYear", connection);
MySqlCommand sCarCT = new MySqlCommand("Select TotalCarCount from Table.CarTotals where sMonth = @sMonth", connection);
MySqlCommand target = new MySqlCommand("Select Target from Table.Targets where Location = 'xxxxx'", connection);
try
{
connection.Open();
cmd.Parameters.Add(new MySqlParameter("sMonth", sMonth));
cmd.Parameters.Add(new MySqlParameter("sYear", sYear));
sCR.Parameters.Add(new MySqlParameter("sMonth", sMonth));
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
dtGrid.DataContext = dt;
Value = double.Parse(sCarCT.ExecuteScalar().ToString());
ValueT = double.Parse(target.ExecuteScalar().ToString());
Value75 = ValueT - ValueT*25%;
Value50 = ValueT - ValueT*50%;
Value25 = ValueT - ValueT*75%;
DataContext = this.Value, this.ValuT, this.Value25, this.Value50, this.Value75;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}
public double Value
{
get { return _value; }
set
{
_value = value;
}
}
public double ValueT
{
get { return _value; }
set
{
_value = value;
}
}
public double Value75
{
get { return _value; }
set
{
_value = value;
}
}
public double Value50
{
get { return _value; }
set
{
_value = value;
}
}
public double Value25
{
get { return _value; }
set
{
_value = value;
}
}
}
귀하의 질문은 특히 좋은 [mcve]을 부족, 매우 광범위하다. 그러나'MainWindow' 클래스에서'INotifyPropertyChanged'를 구현 한 것으로 보이지 않습니다. 이러한 속성에 대해 별도의 뷰 모델 클래스를 만드는 것이 더 좋지만 바인딩이 초기화 된 후에 설정된 값을 바인딩에 반영하려면 속성이 속한 클래스가 INotifyPropertyChanged를 구현해야합니다. –
안녕하세요 피터! 나는 지침을 따르지 못해 죄송합니다. 첫 번째 예제는 검증 가능하고 작동합니다. 그러면 두 번째 목표는 내가 성취하려는 것을 번역하는 방법입니다. 나는 정확하게 쓰는 법을 모르며 당신 같은 사람을 믿었습니다. 나를 도울 지식이있는 사람입니다. 귀하의 신속한 제안에 감사드립니다. – iCosmin
문제는 특수 게이지 또는 LiveCharts와 관련이 없습니다. 좋은 스택 오버 플로우 문제를 만들기 위해, 당신은 가지고있는 문제를 보여주기 위해 필요한 최소한의 코드로 기본 이슈를 추출하는 코드 예제를 제공해야합니다. 또는 WPF 및 데이터 바인딩에 대한 많은 자습서를 읽을 수 있습니다. 그것은 또한 작동 할 것입니다. –